WindowsBatch与LinuxShell比较[shell循环范例]

WindowsBatch与LinuxShell比较[shell循环实例]

WindowsBatch与LinuxShell比较[shell循环实例]

 

Shell的循环实例:

WindowsBatch与LinuxShell比较[shell循环范例]
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for i in 12345
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
echo"Welcome $i times"
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for i in $(seq 115)
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
echo"Welcome $i times"
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for i in {1..5}
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
echo"Welcome $i times"
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for(( c=1; c<=5; c++))
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
echo"Welcome $c timesWindowsBatch与LinuxShell比较[shell循环范例]"
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for i in $( ls );do
WindowsBatch与LinuxShell比较[shell循环范例]
echo item: $i
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for i in `seq 110`;
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
echo$i
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
for file in /etc/*
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
if [ "${file}"=="/etc/resolv.conf" ]
WindowsBatch与LinuxShell比较[shell循环范例]
then
WindowsBatch与LinuxShell比较[shell循环范例] countNameservers
=$(grep -c nameserver /etc/resolv.conf)
WindowsBatch与LinuxShell比较[shell循环范例]
echo"Total ${countNameservers} nameservers defined in ${file}"
WindowsBatch与LinuxShell比较[shell循环范例]
break
WindowsBatch与LinuxShell比较[shell循环范例] fi
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]
FILES="$@"
WindowsBatch与LinuxShell比较[shell循环范例]
for f in $FILES
WindowsBatch与LinuxShell比较[shell循环范例]
do
WindowsBatch与LinuxShell比较[shell循环范例]
#if.bak backup file exists, read next file
WindowsBatch与LinuxShell比较[shell循环范例]
if [ -f ${f}.bak ]
WindowsBatch与LinuxShell比较[shell循环范例]
then
WindowsBatch与LinuxShell比较[shell循环范例]
echo"Skiping $f fileWindowsBatch与LinuxShell比较[shell循环范例]"
WindowsBatch与LinuxShell比较[shell循环范例] continue
# read next file and skip cp command
WindowsBatch与LinuxShell比较[shell循环范例] fi
WindowsBatch与LinuxShell比较[shell循环范例]
# we are hear means no backup file exists, just use cp command to copy file
WindowsBatch与LinuxShell比较[shell循环范例]
/bin/cp $f $f.bak
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]COUNTER
=0
WindowsBatch与LinuxShell比较[shell循环范例]while [
$COUNTER -lt 10 ];do
WindowsBatch与LinuxShell比较[shell循环范例]
echo The counter is $COUNTER
WindowsBatch与LinuxShell比较[shell循环范例] let COUNTER
=COUNTER+1
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]
#!/bin/bash
WindowsBatch与LinuxShell比较[shell循环范例]COUNTER
=20
WindowsBatch与LinuxShell比较[shell循环范例]until [
$COUNTER -lt 10 ];do
WindowsBatch与LinuxShell比较[shell循环范例]
echo COUNTER $COUNTER
WindowsBatch与LinuxShell比较[shell循环范例] let COUNTER-
=1
WindowsBatch与LinuxShell比较[shell循环范例]done
WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环范例]

完!

感谢,Thanks!

作者:iTech
出处:http://itech.cnblogs.com/