Solved

passing parameters between scripts.

Posted on 2001-07-13
6
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 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 84

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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