Positional arguments

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}.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: