pass arguments between shell scripts but retain quotes

前端 未结 1 777
心在旅途
心在旅途 2021-02-01 16:13

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:



        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 17:01

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

    ./script2.sh "$@"
    

    More info:

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

    $*
    All of the positional parameters, seen as a single word

    Note: "$*" must be quoted.

    $@
    Same as $*, but each parameter is a quoted string, that is, the parameters are passed on intact, without interpretation or expansion. This means, among other things, that each parameter in the argument list is seen as a separate word.

    Note: Of course, "$@" should be quoted.

    0 讨论(0)
提交回复
热议问题