what does $* mean in a shell script

那年仲夏 提交于 2019-12-19 00:25:34

问题


What does $* exactly mean in a shell script?

For example consider the following code snippet

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

回答1:


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.




回答2:


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:


$* 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



来源:https://stackoverflow.com/questions/12413848/what-does-mean-in-a-shell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!