~/ learn/ comp-325/ cards/ foreach, switch, and one-based arrays
1 of 10

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)

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/aeececb3-1e70-4048-a0d0-c92697b4d502/flashcard utf-8 LF