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


bash 4.2 show assumed correct behavior in c-style loop:

me@server:/some/dir# times=30; (( n=0; n<$(shuf -i ${times}-$(expr ${times} + 20) -n 1); n++ )); 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# 

the same under bash 4.3 throws error:

me@server:/some/dir# times=30; (( n=0; n<$(shuf -i ${times}-$(expr ${times} + 20) -n 1); n++ )); 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) (...) 

yet part find random number between ${times} , ${times}+20 works:

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

so inserting numeral directly instead of $()-subshell'ing it:

me@server:/some/dir# times=30; (( n=0; n<26; n++ )); 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# 

what's going on here? ideas why subshell not executed correctly under bash 4.3?

if replace $(expr $((, starts work:

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

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -