bash - bash 中 "$*"有哪些用例?

标签 bash parameters arguments command-line-arguments

来自 bash 手册页:

"$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable.

"$@" is equivalent to "$1" "$2" ...

有没有 "$@" 不能代替 "$*" 的例子?

最佳答案

我最喜欢的用途是替换字段分隔符。

$ set -- 'My word' but this is a bad 'example!'
$ IFS=,
$ echo "$*"
My word,but,this,is,a,bad,example!

还有其他替换定界符的方法,但 IFS 和 "$*" 通常是最简单的方法之一。

关于bash - bash 中 "$*"有哪些用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30082852/

相关文章:

bash - 读取 redis-cli 订阅的标准输出并在消息上运行 bash 命令

bash - While 循环在 Bash 中的第一行之后停止读取

bash 脚本 : find max, 按列分组和排序

java - 当多个重载合法时调用哪个方法?

objective-c - 将参数传递给 Objective C 中的 JSON Web 服务

Java - 在程序启动替代过程中将参数作为键值对传递

python - 获取包含图像的 PDF 页面

java - 具有许多参数的枚举

python - 将命令行参数转发到 Python 中的进程

php - wkhtmltoimage 的参数列表太长错误