1 简介
2 语法
while ( condition )# do something# command 1# command 2end
set i = 1while ( i < 5 )# do something till i < 5# command 1# command 2@ i++ # 注意这里的 @end
foreach n ( 1 2 3 4 5 )#command1#command2end
3 示例
3.1 示例1
# 代码#!/bin/csh# demoloop.csh - Sample loop scriptset j = 1while ( $j <= 5 )echo "Welcome $j times"@ j++end# 运行chmod +x demoloop.csh./demoloop.csh# 结果Welcome 1 timesWelcome 2 timesWelcome 3 timesWelcome 4 timesWelcome 5 times
3.2 示例2
#代码#!/bin/cshecho "Setting name servers...."foreach i ( ns1.cyberciti.biz ns2.cyberciti.biz )echo $iend# 运行结果Setting name servers....ns1.cyberciti.bizns2.cyberciti.biz
3.3 示例3
#!/bin/cshforeach i (*)if (-f $i) thenecho "$i is a file."endifif (-d $i) thenecho "$i is a directory."endifend# 输出结果mycal.pl is a file.skl is a directory.x is a file.x.pl is a file.y is a file.
4 说明
文章转载自微思研,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




