WindowsBatch与LinuxShell比较[shell循环范例]
WindowsBatch与LinuxShell比较[shell循环实例]
Shell的循环实例:
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
for i in 12345
do
echo"Welcome $i times"
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
for i in $(seq 115)
do
echo"Welcome $i times"
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
for i in {1..5}
do
echo"Welcome $i times"
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
for(( c=1; c<=5; c++))
do
echo"Welcome $c times
"
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
for i in $( ls );do
echo item: $i
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
for i in `seq 110`;
do
echo$i
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/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
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/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 cp command
fi
# we are hear means no backup file exists, just use cp command to copy file
/bin/cp $f $f.bak
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
COUNTER=0
while [ $COUNTER -lt 10 ];do
echo The counter is $COUNTER
let COUNTER=COUNTER+1
done
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
![WindowsBatch与LinuxShell比较[shell循环范例] WindowsBatch与LinuxShell比较[shell循环范例]](/default/index/img?u=aHR0cDovL3d3dy5teWV4Y2VwdGlvbnMubmV0L2ltZy8yMDEzLzAxLzE4LzExMDQyNTEwMjcuZ2lm)
#!/bin/bash
COUNTER=20
until [ $COUNTER -lt 10 ];do
echo COUNTER $COUNTER
let COUNTER-=1
done
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
完!
WindowsBatch与LinuxShell比较[shell循环实例]
Shell的循环实例:
完!
感谢,Thanks!
作者:iTech
出处:http://itech.cnblogs.com/