Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loosing arguments in KSH script

Status
Not open for further replies.

DGRFL

Programmer
Dec 28, 2000
36
BE
Hello,

The following script one.sh calls second.sh using the '.' operator (in order to retain environment variables defined in second.sh)

After the execution of second.sh, the original command line arguments $1,etc are lost.

#!/usr/bin/ksh
# first.sh : call this script with arguments a,b,c,d,e
echo parm5 $5
# output is 'e'
one=$1
second.sh $one
echo parm5 $5
# output is 'e'
. second.sh $one
echo parm5 $5
# output is blank


#!/usr/bin/ksh
# second.sh : this script is called by first.sh
echo second shell $1


How can we avoid this problem ? (Saving the arguments in additional variables $p1, $p2, ... would work, but I don't like this solution)


Best regards,

Luc
 
could you try

. second.sh $*
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hello,
I tried your suggestion $*, and it is an improvement but no complete solution.

- In first instance, the 'original production version' of second.sh script calls other scripts (among others .profile) with the dot operator, so I have to pass $* throughout the complete shell script tree.

- The arguments that are to be passed are not a,b,c,d,e but the fifth argument contains embedded blanks. So this is the new version of first.sh

#!/usr/bin/ksh
# first.sh : call it as first.sh a b c d 'e e'
echo parm5 $5
# output is 'e e' (without the quotes) as expected
second.sh $*
echo parm5 $5
# output is 'e e'
. second.sh $*
echo parm5 $5
# output is 'e'

Why have I lost the second part of the argument ?

Regards
Luc
 
From another post in this forum -- try

first.sh a b c d "'e e'"

(enclose the single quoted string in double quotes) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hello,

It is an improvement, but we need to use these scripts combined with 'rsh', and then it becomes a terrible mess.

I will adapt the $1, $2... with $p1,$p2. It is not a nice solution, but it works.

Thanks for the advice

Luc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top