bash $* 在 shell 脚本中是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12413848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:16:35  来源:igfitidea点击:

what does $* mean in a shell script

linuxbashshellunixspecial-characters

提问by Subin_Learner

What does $*exactly mean in a shell script?

$*在 shell 脚本中到底是什么意思?

For example consider the following code snippet

例如考虑以下代码片段

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

采纳答案by Ignacio Vazquez-Abrams

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.

它通常是错误的,应该替换为"$@",它可以正确分隔参数。

回答by ДМИТРИЙ МАЛИКОВ

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

自己找答案很容易: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 IFSspecial variable. That is, "$*"is equivalent to "$1c$2c...", where cis the first character of the value of the IFSvariable. If IFSis unset, the parameters are separated by spaces. If IFSis null, the parameters are joined without intervening separators.

特殊参数

shell 对几个参数进行了特殊处理。这些参数只能被引用;不允许分配给他们。

  • 扩展到位置参数,从 1 开始。当扩展发生在双引号内时,它扩展为单个单词,每个参数的值由IFS特殊变量的第一个字符分隔。也就是说,"$*"相当于 "$1c$2c...",其中 cIFS变量值的第一个字符。如果IFS未设置,则参数以空格分隔。如果IFS为 null,则连接参数而不插入分隔符。

回答by Jin Kim

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

$*扩展到传递给该 shell 脚本的所有参数。

$0= shell script's name

$0= shell 脚本的名称

$1= first argument

$1= 第一个参数

$2= second argument ...etc

$2= 第二个参数...等

$#= number of arguments passed to shellscript

$#= 传递给 shellscript 的参数数量