Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
syntax:ccmd:classic_for [2017/01/19 21:43]
4dummies Added another form
syntax:ccmd:classic_for [2017/01/19 22:02] (current)
4dummies [Loop over a number range] removed a stray "1"
Line 128: Line 128:
 ==== Loop over a number range ==== ==== Loop over a number range ====
  
-You can also use the {a..b} syntax with the for-in ​form when you looping over numbers ​(verified in Bash 4 anyway), and this form does not create leading zeroes:+Beginning in Bash 4, you can also use "​sequence expression" ​form of [[syntax:​expansion:​brace|brace expansion]] syntax ​when looping over numbers, and this form does not create leading zeroes ​unless you ask for them:
  
 <code bash> <code bash>
 +# 100 numbers, no leading zeroes
 for x in {0..99}; do for x in {0..99}; do
 +  echo $x
 +done
 +</​code>​
 +
 +<code bash>
 +# Every other number, width 3
 +for x in {000..99..2};​ do
   echo $x   echo $x
 done done