Tuesday, August 20, 2013

Shell Loop Example

#!/bin/csh
# demoloop.csh - Sample loop script
set j = 1
while ( $j <= 5 )
echo "Welcome $j times"
@ j++
end

output

----------------

Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times

===================

 

foreach i (*)
if (-f $i) then
echo "$i is a file."
endif
if (-d $i) then
echo "$i is a directory."
endif
end

----------------------------

mycal.pl is a file.
skl is a directory.
x is a file.
x.pl is a file.
y is a file.

No comments:

Post a Comment