Solved

passing parameters between scripts.

Posted on 2001-07-13
6
547 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

749 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