如何将一个shell脚本的所有参数传递给另一个?我试过$ *,但正如我所料,如果你引用的参数,这不工作。
例:
$ 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
我想打印出来:
apple pear orange banana
使用“$ @”而不是$ *来保留引号:
./script2.sh "$@"
更多信息:
http://tldp.org/LDP/abs/html/internalvariables.html
$*
All of the positional parameters,seen as a single wordNote: “$*” 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.