Positional parameter passing

Hi All,

When passing parameters to a sheel script, the parameters are referenced by their positions such as $1 for first parameter, $2 for second parameter. these positional values can only have values ranging from $0-$9 (0,1,2,3...9).

I have a shell script meant to accept 20 parameters. for example:

./myscript.sh inp1 inp2 inp3 inp4 inp5 inp6 inp 7 inp8 inp10 inp11 inp12 inp13

Since positional parameters only have values ranging from $0-$9, how can l reference parameters $10,$11,$12 and above? I have tried using $10,$11 and $12,the parameters were not passed.

Any idea would be appreciated?

Thanks

There are 2 more:

  • $* holds all parameters passed in one variable
  • $@ is an array of all parameters passed.

Hi Pludi,

That works perfectly!

Thanks!

You must use curly brackets for parameters greater that 9, see example:

# cat test.sh
#!/bin/sh
echo $@
echo $18
echo ${18}

# ./test.sh a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a8
r