bash-guide
bash-guide copied to clipboard
Add for using brace or nested brace expansion
There is an other use of for
, it's very useful in some case
for char in {a..z}; do
echo$ char
done
It will be print a b c ... x y z
or
for i in {{a..m},{0..9},{n..z}}; do # don't have any space between commas
echo $i
done
It will be print a b c ... k l m 0 1 2 ... 7 8 9 n o u ... x y z
For anyone like me seeing this while searching through GitHub, this is not a feature of the for
loop itself, but a general feature called brace expansion. This is useful in a great many ways, such as during file operations with glob filename pattern matching and in the situation posted here.