1
我试图将脚本从BASH移植到ASH(Almquist SHell),并且遇到间接引用的问题。当下ASH(或DASH)运行:下面的函数ASH可变间接引用
cmd() {
# first argument is the index to print (ie label)
arg=$1
# ditch the first argument
shift
# print the label (via indirect reference)
echo "${!arg}"
}
应该产生以下输出
cmd 1 one two three
one
cmd 2 one two three
two
cmd 3 one two three
three
这工作下bash作为预期,但产生一个“错误的替换语法错误”。这应该工作吗?如果没有,是否有替代使用间接引用?
这几乎正是我来到了刚刚发布 回声后 “$(EVAL回声\ $$ ARG)” – ctuffli 2009-06-18 20:06:56