Solved

passing parameters between scripts.

Posted on 2001-07-13
6
540 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 521
Replacement selected text 2 58
has22 challenge 11 78
Fibonacci challenge 11 108
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

930 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

12 Experts available now in Live!

Get 1:1 Help Now