command line arguments - Storing ksh input array to variable and passing to another script -
i have modify existing ksh script looks @ command-line arguments using 'shift', , empties $@, want pass original arguments second script afterwards.
in mainline case can coping $@ variable , passing second script, can't work quoted command-line arguments.
if have script called 'printer' below:
#!/bin/ksh input=$@ echo "printing args" until [[ $# -eq 0 ]];do echo $1 shift done ./printer2 $input
and printer2 below:
#!/bin/ksh echo "printing second args" until [[ $# -eq 0 ]];do echo $1 shift done
i output of
./printer first second "third forth"
to :
printing args first second third forth printing second args first second third forth
i've tried various combinations of quotes around variables (both in assignment of $input , when passing printer2) can't figure out. can help?
ok think i've found solution after awful lot of trial , error.
assigning $input this:
set -a input "$@"
and passing this:
./printer2 "${input[@]}"
produces output i'm after.
the whole first script therefore:
#!/bin/ksh set -a input "$@" echo "printing args" until [[ $# -eq 0 ]];do echo $1 shift done ./printer2 "${input[@]}"
and
./printer first second "third fourth"
outputs:
printing args first second third fourth printing second args first second third fourth
if wants explain problem other things tried, please do, i'm still interested!
Comments
Post a Comment