Positional arguments

July 11, 2007

A tutorial reader, Maarten Zeinstra, emailed me the other day about Variables – Part II, where I "kinda implicitly state that there are only 9 available params to be given in any program $1..$9 so if you wanted do have more then those you might want to do something like your example. But ${n} also works to get above 9 params."

It turns out that this is entirely true – for bash, dash, csh, ksh, and probably other shells too. The ${9} limitation seems only to apply to the traditional Bourne shell – that is, #!/bin/sh on commercial Unices.

If you can be sure that your script will be interpreted by bash, or similar, you can quite happily refer to your tenth argument as ${10}.