命令替换得到$((2+3))为什么没有继续扩展?

命令替换得到$((2+3))为什么没有继续扩展?

# generateArithmeticExpand 
generateArithmeticExpand() {
    echo '$((2+3))'
}

echo $(generateArithmeticExpand)
# => $((2+3))

for i in $(generateArithmeticExpand)
do    
    echo $i
done

# => $((2+3))

在展开的顺序中arithmetic expandcommand substitution之后进行的,为什么arithmetic expand没有执行呢?

如果这里的命令替换得到的是*,它是会继续进行filename expand的。

阅读 1k
1 个回答

bash

The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and pathname expansion.

arithmetic expansion 在 command substitution 之前。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进