bash – 如何结合算术扩展和大括号扩展?

参见英文答案 > In bash, is it possible to use an integer variable in the loop control of a for loop?                                    4个
人们可以结合算术扩展和支撑扩展吗?

$for i in {$((1 + 1))..5}; do echo $i; done;
{2..5}
$echo "bash laughs at me"
最佳答案
请参阅man bash获取解释:

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

大括号扩展在算术扩展之前发生,因此您无法以您尝试的方式组合它们.

请改用seq:

for i in $(seq $((a+4)) 12) ; do echo $i ; done

转载注明原文:bash – 如何结合算术扩展和大括号扩展? - 代码日志