Is there a limit to the no. of arguments to a shell script ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Is there a limit to the no. of arguments to a shell script ?
# 1  
Old 03-17-2008
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  
Old 03-17-2008
yes - should be possible.

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

should be what you want.
# 3  
Old 03-17-2008
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  
Old 03-17-2008
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  
Old 03-17-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

2. Shell Programming and Scripting

sub arguments to shell script

Hi, I have a shell script, when run it i get a prompt to enter arguments say 1 for doing my next task otherwise q for quit. What I am trying to do is run the shell script with the argument passed in however it does not seem to work. This is what I did ./test.sh 1 Instead it printed the line... (6 Replies)
Discussion started by: aqua9
6 Replies

3. Shell Programming and Scripting

Using arguments in Shell script

Hello, I have to make a shell script doing that : the program tests if there is an argument, if there is it checks whether this is a directory or not, If it is it opens it. for any .c file in the directory it prints 2 lines in the screen : the dependence line of the .o and compiler commend... (1 Reply)
Discussion started by: dekl
1 Replies

4. Shell Programming and Scripting

How to remove a file in shell script if its size exceeds limit?

How can i remove a file using shell script when its size exceeds 10MB. Given that file is located in different location to the shell script where it is running? (4 Replies)
Discussion started by: vel4ever
4 Replies

5. Shell Programming and Scripting

csh shell script 'set' argument limit?

Hi , I have a script that is causing a problem that led me to think if there is a limit to the number of arguments for 'set' command in csh shell script. Here is my script: #!/bin/csh -f set top = design_top #1 set v_mbist = ( sim_mbist/*.v ) #2 set v_simlist = ( -v... (2 Replies)
Discussion started by: return_user
2 Replies

6. Shell Programming and Scripting

Shell script command line arguments

Hello All, i am known to the limitation of different shells while passing more than 9 command line arguments i just tried the example below i do see my current shell is tcsh echo $SHELL /bin/tcsh so if i make my script executable and run it output is ... (6 Replies)
Discussion started by: Deepak Dutt
6 Replies

7. Shell Programming and Scripting

Limit ouput file on a shell script

I have this one::) doing jstack on JVM proccess. #!/bin/ksh # ---------------------------------------------------- # capture_jstack.sh <INTERVAL> <COUNT> # run jstack and capture output to a log file #----------------------------------------------------- # # scripts and logs are stored... (3 Replies)
Discussion started by: pointer
3 Replies

8. Shell Programming and Scripting

no of arguments to function in shell script

Hi, I have a function in shell script fun1{ echo "No.of arguments are..."} this function will be called in same script by passing arguments fun 1 2 3 I want to check the no. of arguments passed to fun1 function in the same functionbefore validation. can any one suggest me. (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

9. Shell Programming and Scripting

Need help to pass arguments to shell script

Hi, I have a shell script called ftp.sh which is running continously in background. I tried passing arguments to this script but it did not worked out. Below is ftp.sh script. Please help me case $param in start) sleep_func "300" echo "!ksh $scr_ddir/ftp.sh... (1 Reply)
Discussion started by: bhargav20
1 Replies

10. Shell Programming and Scripting

Shell script with arguments

Hi All, I need some help/ideas in coming up with a shell script. Basically, the script should install 1 or 2 or 3 packages based on the input arguments. For example, if I type in pkgscript.sh a1 a2 a3, it should install all the 3 scripts and pkgscript.sh a1 should install only a1. If a... (3 Replies)
Discussion started by: sankar6254
3 Replies
Login or Register to Ask a Question