With increment:

$ for i in {1..20..2}; do echo $i; done

Output:

1
3
5
7
9
11
13
15
17
19
$ for word in one two three; do echo $word; done

Output:

one
two
three

C-like syntax:

$ for ((i=1; i<=4; i++)); do echo "$i"; done

Output:

1
2
3
4
$ for file in $(ls *.dat); do echo "nastran old=no news=no scr=yes $file que=default" >> nastran_run.txt; done

Output:

nastran old=no news=no scr=yes model3_8.dat que=default
nastran old=no news=no scr=yes model3_9.dat que=default
nastran old=no news=no scr=yes model1_1.dat que=default
nastran old=no news=no scr=yes model1_2.dat que=default
nastran old=no news=no scr=yes model1_3.dat que=default
nastran old=no news=no scr=yes model1_4.dat que=default
nastran old=no news=no scr=yes model2_5.dat que=default
nastran old=no news=no scr=yes model2_6.dat que=default
nastran old=no news=no scr=yes model2_7.dat que=default
nastran old=no news=no scr=yes model3_8.dat que=default
nastran old=no news=no scr=yes model3_9.dat que=default
$ for file in $(ls *.{dat,bdf}); do echo "nastran old=no news=no scr=yes $file que=default" >> nastran_run.txt; done
$ rm nastran_run.txt; for file in $(ls *.dat | grep \^model1 ); do echo "nastran old=no news=no scr=yes $file que=default" >> nastran_run.txt; done

Output:

nastran old=no news=no scr=yes model1_1.dat que=default
nastran old=no news=no scr=yes model1_2.dat que=default
nastran old=no news=no scr=yes model1_3.dat que=default
nastran old=no news=no scr=yes model1_4.dat que=default
$ rm nastran_run.txt; for file in $(ls *.dat | grep \^model2 ); do echo "nastran old=no news=no scr=yes $file que=default" >> nastran_run.txt; done

Output:

nastran old=no news=no scr=yes model1_1.dat que=default
nastran old=no news=no scr=yes model1_2.dat que=default
nastran old=no news=no scr=yes model1_3.dat que=default
nastran old=no news=no scr=yes model1_4.dat que=default

Output:

nastran old=no news=no scr=yes model2_5.dat que=default
nastran old=no news=no scr=yes model2_6.dat que=default
nastran old=no news=no scr=yes model2_7.dat que=default
$ rm nastran_run.txt; for file in $(ls *.dat | grep \^model2 ); do echo "nastran old=no news=no scr=yes $file que=default" >> nastran_run.txt; done

Output:

nastran old=no news=no scr=yes model3_8.dat que=default
nastran old=no news=no scr=yes model3_9.dat que=default

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading