views:

258

answers:

1

How do I pass all the arguments of one shell script into another? I have tried $*, but as I expected, that does not work if you have quoted arguments.

Example:

$ cat script1.sh

#! /bin/sh
./script2.sh $*

$ cat script2.sh

#! /bin/sh
echo $1
echo $2
echo $3

$ script1.sh apple "pear orange" banana
apple
pear
orange

I want it to print out:

apple
pear orange
banana
+3  A: 

Use "$@" instead of $* to preserve the quotes:

./script2.sh "$@"

More info:

http://tldp.org/LDP/abs/html/internalvariables.html

ZoogieZork
Thanks, that worked.
dogbane