- مدل اول
|
1 2 3 |
for (( i=1 ; i <= 10 ; i++ )) ; do echo $i done |
- مدل دوم
|
1 2 3 4 5 6 |
for VARIABLE in 1 2 3 4 5 .. N do command1 command2 commandN done |
- مدل سوم
|
1 2 3 4 5 6 |
for VARIABLE in file1 file2 file3 do command1 on $VARIABLE command2 commandN done |
- مدل چهارم
|
1 2 3 4 5 6 |
for OUTPUT in $(Linux-Or-Unix-Command-Here) do command1 on $OUTPUT command2 on $OUTPUT commandN done |
- مدل پنجم
|
1 2 3 4 5 |
#!/bin/bash for i in 1 2 3 4 5 do echo "Welcome $i times" done |
- مدل ششم
|
1 2 3 4 5 |
#!/bin/bash for i in {1..5} do echo "Welcome $i times" done |
- مدل هفتم
|
1 2 3 4 5 6 |
#!/bin/bash echo "Bash version ${BASH_VERSION}..." for i in {0..10..2} do echo "Welcome $i times" done |
- مدل هشتم
|
1 2 3 4 5 |
#!/bin/bash for i in $(seq 1 2 20) do echo "Welcome $i times" done |
- مدل نهم
|
1 2 3 4 5 |
#!/bin/bash for (( ; ; )) do echo "infinite loops [ hit CTRL+C to stop]" done |
- مدل دهم
|
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash for file in /etc/* do if [ "${file}" == "/etc/resolv.conf" ] then countNameservers=$(grep -c nameserver /etc/resolv.conf) echo "Total ${countNameservers} nameservers defined in ${file}" break fi done |
- مدل یازدهم
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/bash FILES="$@" for f in $FILES do # if .bak backup file exists, read next file if [ -f ${f}.bak ] then echo "Skiping $f file..." continue # read next file and skip the cp command fi # we are here means no backup file exists, just use cp command to copy file /bin/cp $f $f.bak done |