shift command

Hi Folks,

In shell scripting the maximum no. of command line parameters becomes 9(Am i right). If we want to get more than 9 parameters we use the shift command.

Even here there are two possibilities.

  1. Without the use of variables - The arguments are lost and the lost no. is equal to the shift in position.

  2. With the use of variables - store the shifted positional parameters in temporary variables like $a, b,c etc. I dont think that this is a nice practice.

But i need some other efficient way of handling these command line parameters. Why is it that shell supports only 9 positional parameters? Why not more???

Thanks in Advance,
Nisha

This is where I got my method for dealing with command line parameters.

http://www.shelldorado.com/

Don't know why you're only allowed 9 though.

Hey Thanks kevin.. While i am still puzzled.

-Nisha

The exact cutoff point has to do with making the shell easy to code. $10 really would not be easy to support.

But when there are more than a few parameters, the expectation is that the programmer will use a loop. And once you go to a loop, $1 is all you need. In ksh this looks like...

while (($#)) ; do
       # do something with $1
       shift
done

By the time you do the "shift" you should be finished with $1 and you don't care that it's going away.

ksh also has a getopts built-in command to assist with parameter processing. See this post for an example.

Yes I did look at this loop methodology of handling it. Is there not any other alternate way???

Thanks,
Nisha

Perhaps you could try this

group your parameters by using quotes, like this

"var1 var2 var3 var4" "var5 var6 var7 var8 var9 var10"

Now your script will think you only got 2 parameters.

After this you can work with the parameters as long as you whish by using cut

echo $1 | cut -d" " -f2
to get var2

This way you can use as many parameters as you want in your scripts whithout loosing one

:smiley:

Hey Thanks!!!

Sounds like a good one..

Thanks,
Nisha