Conditional Expressions

This section summarizes conditional expressions or tests. Conditional expressions are mainly used with the test command in conjunction with if statements and while and until loops.

File Tests

The following conditional expressions are used to perform file and directory related tests.

-a file true if file exists (ksh, bash, and zsh only)
-b file true if file is a block special device
-c file true if file is a character special device
-d dir true if dir is a directory
-e file true if file exists
-f file true if file is a regular file
-g file true if file has the SGID permission bit set
-G path true if path exists and its group matches the user's current group ID (Linux and BSD systems only)
-h file true if file is a symbolic ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.