January 2003
Intermediate to advanced
832 pages
32h 40m
English
foreach
name(wordlist)commands
Assign variable name to each value in
wordlist and execute
commands between
foreach and end. You can use
foreach as a multiline command issued at the
C-shell prompt (see the first of the following examples), or you can
use it in a shell script (see the second example).
Rename all files that begin with a capital letter:
%foreach i ([A-Z]*)?mv $i $i.new?end
Check whether each command-line argument is an option or not:
foreach arg ($argv)# does it begin with - ?if ("$arg" =~ -*) thenecho "Argument is an option"elseecho "Argument is a filename"endifend