bash 4.2 / 4.3:C 风格循环中的不同行为

bash 4.2 / 4.3: Different behavior in C-style loop

bash 4.2 显示 C 风格 for 循环中假设的正​​确行为:

me@server:/some/dir# TIMES=30; for (( n=0; n<$(shuf -i ${TIMES}-$(expr ${TIMES} + 20) -n 1); n++ )); do echo $n; done
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
me@server:/some/dir# bash --version
GNU bash, Version 4.2.25(1)-release (x86_64-pc-linux-gnu)
(...)
me@server:/some/dir#

同样在bash 4.3下报错:

me@server:/some/dir# TIMES=30; for (( n=0; n<$(shuf -i ${TIMES}-$(expr ${TIMES} + 20) -n 1); n++ )); do echo $n; done
-bash: syntax error near unexpected token `newline'
me@server:/some/dir# bash --version
GNU bash, Version 4.3.30(1)-release (x86_64-pc-linux-gnu)
(...)

然而,找到 ${TIMES}${TIMES}+20 之间的随机数的部分有效:

me@server:/some/dir# shuf -i 20-50 -n 1
26
me@server:/some/dir#

直接插入数字而不是 $()-subshel​​l'ing 也是如此:

me@server:/some/dir# TIMES=30; for (( n=0; n<26; n++ )); do echo $n; done
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
me@server:/some/dir#

这是怎么回事?为什么子 shell 在 bash 4.3 下不能正确执行的任何想法?

如果将 $(expr 替换为 $((,它将开始工作:

TIMES=30
for (( n=0; n < $(shuf -i $TIMES-$((TIMES + 20)) -n 1); n++ )) ; do
    echo $n
done