【发布时间】:2019-08-17 00:54:39
【问题描述】:
在 ash/dash 函数中,我可以像这样引用完整的参数列表:
allparameters() { echo "$@"; }
这给了我:
$ allparameters yyyyy abffcd efgh
yyyyy abffcd efgh
我想跳过yyyyy,所以我尝试了${@:2}:
butlast() { echo "${@:2}"; }
但是,这会跳过前两个字符:
$ butlast yyyyy abffcd efgh
yyy abffcd efgh
$ butlast abffcd efgh
ffcd efgh
我无法在 the man page 中找到 ash 的冒号语法,所以这可能是 bash 主义。什么是等价物?
【问题讨论】:
-
看起来
ash正在将:应用于由位置参数形成的单个字符串,而不是参数的“数组”。不确定这是错误还是预期(但未记录)的行为。在dash中,这只是一个“错误替换”错误。 -
有趣。谢谢你的上下文。
标签: shell ash dash-shell