Pass all the parameters of one shell script to another

I have a shell script to which I pass several parameters. Test1.sh -a 1 -b 2 -c "One Two Three"

Inside Test1.sh, I call another shell script below. Test2.sh $*

I want to pass all the Test2 parameters that were passed to Test1, also in the same format (with double quotes, etc.). However, the parameters that are passed to Test2 are Test2.sh -a 1 -b 2 -c One Two Three which does not work for me. Is there a way around it so that I can pass parameters just like I pass Test1.

Thanks Zabi

+4
source share
1 answer

You need to say:

 Test2.sh " $@ " 

Refer to Special Settings :

@

Expands to positional parameters, starting with one. When expansion occurs in double quotes, each parameter is expanded to a single word. That is, " $@ " equivalent to "$1" "$2" ... If double quoted expansion occurs inside a word, the extension of the first parameter is connected to the initial part of the original word, and the extension of the last parameter is connected to the last part of the original word. When there are no positional parameters, " $@ " and $@ expanded to zero (that is, deleted).

The manual says:

"$*" equivalent to "$1c$2c..." , where c is the first character of the value of the IFS variable.

which explains the result you are observing.

+10
source

Source: https://habr.com/ru/post/1499432/


All Articles