Linux csh Shell循环
时间:2019-11-20 08:53:18 来源:igfitidea点击:
C外壳(csh)while循环 foreach循环示例
语法
语法如下:
while(condition) command1 command2 end
set i = 1
while ( i < 5 )
command1
command2
@ i++
end
或者
foreach n(1 2 3 4 5) command1 command2 end
csh Shellwhile循环示例
csh while循环:
#!/bin/csh set j = 1 while ( $j <= 5 ) echo "Hello $j times" @ j++ end
csh foreach循环示例
#!/bin/csh foreach i ( server1 server2 ) echo $i end
对foreach使用通配符:
#!/bin/csh
foreach i (*)
if (-f $i) then
echo "$i is a file."
endif
if (-d $i) then
echo "$i is a directory."
endif
end

