I have a shell script to which i am passing few parameters.
Test1.sh -a 1 -b 2 -c "One Two Three"
Inside Test1.sh i am calling another shell script in the below fashion.
Test2.sh $*
I want to pass all the parameters to Test2, that were passed to Test1 and also in the same format (with double quotes etc).
However the parameters that get passed to Test2 are
Test2.sh -a 1 -b 2 -c One Two Three
which doesnt work for me. Is there a way around it so that i can pass the parameters the same way as I am passing to Test1.
Thanks Zabi
You need to say:
Test2.sh "$@"
Refer to Special Parameters:
@
Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is,
"$@"
is equivalent to"$1" "$2" ...
. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters,"$@"
and$@
expand to nothing (i.e., they are removed).
The manual says:
"$*"
is equivalent to"$1c$2c..."
, wherec
is the first character of the value of theIFS
variable.
which explains the result you're observing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With