In the csh
shell, you can use a loop to perform a set of commands multiple times. Here are a few examples of loops in csh
:
- For loop:
set i = 1
while ( $i <= 10 )
echo "Iteration $i"
@ i++
end
This script will print “Iteration 1” to “Iteration 10”.
- For loop with a range:
foreach i ( 1 2 3 4 5 6 7 8 9 10 )
echo "Iteration $i"
end
This script will print “Iteration 1” to “Iteration 10”.
- For loop with command substitution:
foreach i ( `seq 1 10` )
echo "Iteration $i"
end
This script will print “Iteration 1” to “Iteration 10”.