~/ learn/ comp-325/ cards/ test, brackets and conditional branching
1 of 11

The file inspector, compressed to its elif chain

The file inspector, compressed to its elif chain

Answer

if [ ! -e "$f" ]; then echo "missing" elif [ -d "$f" ]; then echo "directory" elif [ -s "$f" ]; then echo "non-empty file" else echo "empty or special" fi

Semicolons let then sit on the same line as the test; the multi-line form in the prose means exactly the same thing. The existence test has to come first because every later operator assumes the name resolves.

S&K 3e ch12 §12.6.1, §12.6.6

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/bdc0a3f5-056a-4ce8-b860-5e01a8c37eb6/flashcard utf-8 LF