语法的KSH

时间:2020-01-09 10:41:09  来源:igfitidea点击:

您能解释一下UNIX ksh for循环语法,它可以通过一个简单的ksh脚本示例重复执行语句块吗?

UNIX ksh语法如下:

for var in item1 item2 item3 ... itemN
do
      command1
      command2
      ...
      commandN
done

这是一个示例示例:

#!/usr/bin/ksh
for character in  Tom Jerry Spike Tyke  Butch Tuffy  Quacker 
   do
   print "Tom and Jerry character is: $character"
done

输出示例:

Tom and Jerry character is: Tom
Tom and Jerry character is: Jerry
Tom and Jerry character is: Spike
Tom and Jerry character is: Tyke
Tom and Jerry character is: Butch
Tom and Jerry character is: Tuffy
Tom and Jerry character is: Quacker

有关循环示例(包括显式列表)和使用ksh进行循环的命令替换的更多信息,请参见此页面。