I stumbled across this oddity and can't quite figure out why it works:
$ for ((i=0;i<8;i++)) {
> printf '%d...' "$i";
> }; echo
0...1...2...3...4...5...6...7...
A for
loop in bash using brace syntax? I can't reproduce this using a non-arithmetic for
loop at all, and the manpage and help
both seem to require the do
:
$ help for
<SNIP>
for ((: for (( exp1; exp2; exp3 )); do COMMANDS; done
Arithmetic for loop.
Equivalent to
(( EXP1 ))
while (( EXP2 )); do
COMMANDS
(( EXP3 ))
done
Hmm, so if I just…
$ ((i=0)); while ((i<8)) { printf '%d...' "$i"; ((i++)); }
-bash: syntax error near unexpected token `{'
Nope!
Is this braced for-loop
syntax
- Documented anywhere (official?)
- A legitimate different way to represent an arithmetic for loop in Bash?
- Just something I'm missing about how a "normal" arithmetic for loop is interpreting the input?
P.S. – This was tested on OS X Mavericks with both a homebrew-installed Bash 4.2.45(2)-release as well as the vanilla 3.2.51(1)-release.