?
Solved

passing parameters between scripts.

Posted on 2001-07-13
6
Medium Priority
?
561 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 200 total points
ID: 6281798
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
ID: 6282263
thanks ahoffman, but what you mean by "shift the parameters" ?

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

SIDCAP
0
 
LVL 85

Expert Comment

by:ozo
ID: 6282945
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 51

Expert Comment

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

Expert Comment

by:superschlonz
ID: 6283601
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
ID: 6285578
Thanks colleagues !!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 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