The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-11-2002
Registered User
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Lightbulb 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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-11-2002
Registered User
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
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.
Reply With Quote
  #3 (permalink)  
Old 07-11-2002
Registered User
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Hey Thanks kevin.. While i am still puzzled.

-Nisha
Reply With Quote
  #4 (permalink)  
Old 07-11-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,333
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
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.
Reply With Quote
  #5 (permalink)  
Old 07-11-2002
Registered User
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Smile

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


Thanks,
Nisha
Reply With Quote
  #6 (permalink)  
Old 07-19-2002
Registered User
 

Join Date: Jul 2002
Location: Belgium
Posts: 20
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

Reply With Quote
  #7 (permalink)  
Old 07-19-2002
Registered User
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Hey Thanks!!!

Sounds like a good one..

Thanks,
Nisha
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0