Solved

passing parameters between scripts.

Posted on 2001-07-13
6
537 Views
Last Modified: 2013-12-26
How many parameters am I able to pass between unix scripts ?

for example:

Myscript p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 ..... pn

and then

Myscript looks like:

echo $1
echo $2
echo $3
...
echo $n

Thanks in advance, SIDCAP.
0
Comment
Question by:sidcap
6 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
Comment Utility
depends on your OS *and* shell.
Usually the number of parameters is not the problem (would not say unlimited), but the length of the command line in characters, which is limited to 2048 bytes, sometimes 20kbytes. Some OSs can change this limit using kernel parameters.

Another limit is that positional paremters may only accessed directly using $1 .. $9, while $10 and so on doesn't work in most shells, you need to shift the parameters.
0
 
LVL 3

Author Comment

by:sidcap
Comment Utility
thanks ahoffman, but what you mean by "shift the parameters" ?

I've tried $10, but it means $1 plus "0".

SIDCAP
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Myscript p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14
#!/bin/sh
echo $1
echo $2
echo $3
echo $4
echo $5
echo $6
echo $7
shift 7
echo $1
echo $2
echo $3
echo $4
echo $5
echo $6
echo $7
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
man sh
search for bultin comand shift, then see ozo's example
0
 
LVL 3

Expert Comment

by:superschlonz
Comment Utility
If you don't know the number of parameters you can simply do it in a loop:

#!/bin/sh
while [ -n "$1" ]; do
  echo "$1"
  shift
done

-n means not empty.
0
 
LVL 3

Author Comment

by:sidcap
Comment Utility
Thanks colleagues !!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now