![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Password cannot be circular shift of logonid | sag71155 | HP-UX | 2 | 05-09-2008 02:04 AM |
| Regarding the shift command??? | shrao | Shell Programming and Scripting | 2 | 03-31-2007 12:39 AM |
| Bit shift operator | naan | High Level Programming | 5 | 09-07-2006 11:13 PM |
| xterm SHIFT crazy | oneivan | UNIX for Dummies Questions & Answers | 2 | 06-05-2002 01:29 AM |
| shift command | AkumaTay | UNIX for Dummies Questions & Answers | 1 | 05-20-2002 05:26 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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. |
|
||||
|
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... Code:
while (($#)) ; do
# do something with $1
shift
done
ksh also has a getopts built-in command to assist with parameter processing. See this post for an example. |
|
|||
|
multiple parameters
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 |