sh bash for loops

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh bash for loops相关的知识,希望对你有一定的参考价值。

for VARIABLE in 1 2 3 4 5 .. N
do
	command1
	command2
	commandN
done

for VARIABLE in file1 file2 file3
do
	command1 on $VARIABLE
	command2
	commandN
done

#!/bin/bash
for i in 1 2 3 4 5
do
   echo "Welcome $i times"
done

#!/bin/bash
for i in {1..5}
do
   echo "Welcome $i times"
done

#!/bin/bash
echo "Bash version ${BASH_VERSION}..."
for i in {0..10..2}
  do 
     echo "Welcome $i times"
 done

#!/bin/bash
for (( c=1; c<=5; c++ ))
do  
   echo "Welcome $c times"
done

#!/bin/bash
for (( ; ; ))
do
   echo "infinite loops [ hit CTRL+C to stop]"
done

以上是关于sh bash for loops的主要内容,如果未能解决你的问题,请参考以下文章

sh BASH FOR LOOP零填充

sh Bash:设置-x,for,in,echo,do,done:Debug for Loop使用set xtrace

linux shell scripts:Syntax error: Bad for loop variable

错误处理:Syntax error: Bad for loop variable

sh BASH LOOPS

sh Linux.Bash.Loops