what does $* mean in a shell script

2019-02-13 01:50发布

What does $* exactly mean in a shell script?

For example consider the following code snippet

$JAVA_HOME/bin/java/com/test/Testclass $*

3条回答
我想做一个坏孩纸
2楼-- · 2019-02-13 02:26

It's easy to find answer by yourself: man bash/\$\*:

Special Parameters

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.

  • Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators.
查看更多
劫难
3楼-- · 2019-02-13 02:27

It means all the arguments passed to the script or function, split by word.

It is usually wrong and should be replaced by "$@", which separates the arguments properly.

查看更多
三岁会撩人
4楼-- · 2019-02-13 02:42

$* expands to all parameters that were passed to that shell script.

$0 = shell script's name

$1 = first argument

$2 = second argument ...etc

$# = number of arguments passed to shellscript

查看更多
登录 后发表回答