How do I access arguments to functions if there are more than 9 arguments?
Use :
#!/bin/bashecho ${10}
To test the difference with $10, code in foo.sh :
#!/bin/bashecho $10echo ${10}
Then :
$ ./foo.sh first 2 3 4 5 6 7 8 9 10first010
the same thing is true if you have :
foobar=42foo=FOOecho $foobar # echoes 42echo ${foo}bar # echoes FOObar
Use {}
when you want to remove ambiguities ...
my2c
If you are using bash, then you can use ${10}
.
${...} syntax seems to be POSIX-compliant in this particular case, but it might be preferable to use the command shift
like that :
while [ "$*" != "" ]; do echo "Arg: $1" shiftdone
EDIT: I noticed I didn't explain what shift
does. It just shift the arguments of the script (or function). Example:
> cat script.shecho "$1"shiftecho "$1"> ./script.sh "first arg" "second arg"first argsecond arg
In case it can help, here is an example with getopt/shift :
while getopts a:bc OPT; do case "$OPT" in 'a') ADD=1 ADD_OPT="$OPTARG" ;; 'b') BULK=1 ;; 'c') CHECK=1 ;; esacdoneshift $( expr $OPTIND - 1 )FILE="$1"