I have come across a small script as follows
this is being run asCode:declare -a args=( "$@" ) echo ${#args[@]} #
bash demo1.sh *.pdf
where it is being checked how many pdfs are there in the directory.
I read the man page of bash which says
I am not clear with 2 thingsAn indexed array is created automatically if any variable is assigned to using the syntax name[subscript]=value. The subscript is treated
as an arithmetic expression that must evaluate to a number. If subscript evaluates to a number less than zero, it is used as an offset
from one greater than the array's maximum index (so a subcript of -1 refers to the last element of the array). To explicitly declare an
indexed array, use declare -a name (see SHELL BUILTIN COMMANDS below). declare -a name[subscript] is also accepted; the subscript is
ignored.
what does this means? and what it gets evaluated to what does ("$@") mean and in the second line what doesCode:declare -a args=( "$@" )gets expanded to?what is meant by ${}and args[@] expands to whatCode:echo ${#args[@]} #
Bookmarks