The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing runtime arguments to a shell script... santy Shell Programming and Scripting 10 01-09-2009 10:47 PM
Passing arguments to a shell script from file while scheduling in cron weblogicsupport SUN Solaris 4 01-27-2008 11:16 PM
To Write a Shell script that takes two arguments. bobby36 Shell Programming and Scripting 3 04-05-2007 08:44 PM
How to pass arguments to a function in a shell script? preetikate Shell Programming and Scripting 3 03-01-2004 04:55 AM
Shell script with arguments sankar6254 Shell Programming and Scripting 3 12-22-2003 09:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2008
hidnana hidnana is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 14
Is there a limit to the no. of arguments to a shell script ?

What is the maximum no. of arguments that could be passed to a shell script ? Is there any restriction ?

I've a requirement where I need to pass a list of names to a unix script and I guess the number of such names is not a fixed one. It can run into hundreds.
Is this feasible ?
  #2 (permalink)  
Old 03-17-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 414
yes - should be possible.

have a look at the shift shell built in....i.e. man shift

should be what you want.
  #3 (permalink)  
Old 03-17-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
Yes there's a limit to the max no. of arguments you can pass to a command.
Its system dependent I think. Try this:

Code:
$ getconf ARG_MAX
  #4 (permalink)  
Old 03-17-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
Agreed with Tyatalus that it is system dependent. But tried on posix and bash shell , and the maxmium number of arguments you can pass to a script is 9. If you want to pass more parametrs , you need to use the shift function.

The intresting thing is , more than 9 parameters works fine if numbers are given , but gives unexpected output when tried with letters.

So if you are using some other shell, try testing it with letters.

Thanks!
nua7
  #5 (permalink)  
Old 03-17-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 699
Hi.

Some shells allow access to script parameters using syntax as follows:
Code:
#!/bin/bash -

# @(#) s1       Demonstrate shell script parameter use.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1)

echo
echo " Parameters beyond 9 explicit:"
echo " Parameter 10 is ${10}"
echo " Parameter 11 is ${11}"

echo
echo " Parameters with delayed evaluation using \"eval\":"
for ((j=1;j<=$#;j++))
do
  eval echo " Parameter $j is \${$j}"
done

exit 0
Producing:
Code:
% ./s1 a b c d e f g h i j k
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0

 Parameters beyond 9 explicit:
 Parameter 10 is j
 Parameter 11 is k

 Parameters with delayed evaluation using "eval":
Parameter 1 is a
Parameter 2 is b
Parameter 3 is c
Parameter 4 is d
Parameter 5 is e
Parameter 6 is f
Parameter 7 is g
Parameter 8 is h
Parameter 9 is i
Parameter 10 is j
Parameter 11 is k
However, I think shift is usually the most useful construct ... cheers, drl
Sponsored Links
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0