bash - 括号扩展没有扩展?
bash - brace expansion not expanding?
在 Kubuntu 15.10 上
echo $BASH_VERSION
4.3.42(1)-release
我试试
reps=1
threads={1}{10..60..10}
for((r=0;r<$reps;r++))
do
tCount=0
for t in $threads
do
echo "t=$t, tCount=${tCount}"
#do something funny with it
((tCount++))
done
done
它产生一行
t={1}{10..60..10}, tCount=0
我如何让它工作?
编辑
我希望
t=1, tCount=0
t=10, tCount=1
t=20, tCount=2
t=30, tCount=3
t=40, tCount=4
t=50, tCount=5
t=60, tCount=6
更新
请注意 threads=({1}{10..60..10})
然后是for t in ${threads[@]}
将在 10..60..10
范围前加上字符串 {1}
(即 {1}10,{1}20,..,{1}60
)
{1}
表达式只是一个字符串,因为它不符合大括号扩展语法:
A sequence expression takes the form {X..Y[..INCR]}
, where X and Y are either integers or single characters, and INCR, an optional increment, is an integer.
大括号展开在变量展开之前进行,所以不能仅仅通过引用一个变量来展开大括号:
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 filename expansion.
是直接写大括号展开,还是用eval
(通常不推荐)。
示例:
tCount=0
for t in {1,{10..60..10}}; do
echo "t=$t tCount=$tCount"
(( tCount++ ))
done
在 Kubuntu 15.10 上
echo $BASH_VERSION
4.3.42(1)-release
我试试
reps=1
threads={1}{10..60..10}
for((r=0;r<$reps;r++))
do
tCount=0
for t in $threads
do
echo "t=$t, tCount=${tCount}"
#do something funny with it
((tCount++))
done
done
它产生一行
t={1}{10..60..10}, tCount=0
我如何让它工作?
编辑
我希望
t=1, tCount=0
t=10, tCount=1
t=20, tCount=2
t=30, tCount=3
t=40, tCount=4
t=50, tCount=5
t=60, tCount=6
更新
请注意 threads=({1}{10..60..10})
然后是for t in ${threads[@]}
将在 10..60..10
范围前加上字符串 {1}
(即 {1}10,{1}20,..,{1}60
)
{1}
表达式只是一个字符串,因为它不符合大括号扩展语法:
A sequence expression takes the form
{X..Y[..INCR]}
, where X and Y are either integers or single characters, and INCR, an optional increment, is an integer.
大括号展开在变量展开之前进行,所以不能仅仅通过引用一个变量来展开大括号:
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 filename expansion.
是直接写大括号展开,还是用eval
(通常不推荐)。
示例:
tCount=0
for t in {1,{10..60..10}}; do
echo "t=$t tCount=$tCount"
(( tCount++ ))
done