A foreach over the script's own arguments
A foreach over the script's own arguments
Answer
#!/bin/csh if ($#argv == 0) then echo "usage: $0 file ..." exit 1 endif foreach file ($argv) if (-d file) echo "file: directory" end
The guard on `$#argv` runs before any element is touched, so the subscript error can never fire. The one-line `if` with no `then` is legal because its body is a single simple command.
S&K 3e ch14 §14.7; ch15 §15.2-15.3; csh(1)