If there are more than 9 arguments, then tenth or onwards arguments can't be assigned as $10 or $11. You have to either process or save the $1 parameter, then with the help of shift command drop parameter 1 and move all other arguments down by one. It will make $10 as $9, $9 as $8 and so on.
$# is the number of positional parameters passed to the script, shell, or shell function. This is because, while a shell function is running, the positional parameters are temporarily replaced with the arguments to the function. This lets functions accept and use their own positional parameters.
The reason the braces are needed to access elements beyond element 9 in most POSIX-like shells is because the POSIX standard says so. A positional parameter is a parameter denoted by the decimal value represented by one or more digits, other than the single digit 0.
$(...) allows command substitution, i.e. allows the output of a command to replace the command itself and can be nested.
Use curly braces to set them off:
echo "${10}"
You can also iterate over the positional parameters like this:
for arg
or
for arg in "$@"
or
while (( $# > 0 )) # or [ $# -gt 0 ]
do
echo "$1"
shift
done
You can have up to 256 parameters from 0 to 255 with:
${255}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With