cheat/cheat/cheatsheets/for

36 lines
485 B
Plaintext
Raw Normal View History

2015-12-31 16:15:51 +01:00
# basic loop
for i in 1 2 3 4 5 6 7 8 9 10
do
echo $i
done
# loop ls command results
for var in `ls -alF`
do
echo $var
done
# loop over all the JPG files in the current directory
for jpg_file in *.jpg
do
echo $jpg_file
done
2015-12-31 16:15:51 +01:00
# loop specified number of times
for i in `seq 1 10`
do
echo $i
2016-01-05 03:54:38 +01:00
done
# loop specified number of times: the C/C++ style
for ((i=1;i<=10;++i))
do
echo $i
done
# loop specified number of times: the brace expansion
for i in {1..10}
do
echo $i
done