Conditionals in Bash

Syntax

[[ -<option> <arg> ]] && echo 1 || echo 0

if [[ -<option> <arg> ]]; then
  ...
else
  ...
fi

Conditional Options for Values

-n   string is not null
-z   string is null, that is, has zero length

Conditional Options for File/Folder

Option Description
[ -b "$file" ] Return true if file is a block special file or else false
[ -c "$file" ] Return true if file is a character special file or else false
[ -d "$file" ] Return true if file is a directory or else false
[ -f "$file" ] Return true if file is an ordinary file as opposed to a directory or special file or else false
[ -g "$file" ] Checks if file has its set group ID (SGID) bit set or else false
[ -k "$file" ] Checks if file has its sticky bit set or else false
[ -p "$file" ] Return true if file is a named pipe or else false
[ -t "$file" ] Checks if file descriptor is open and associated with a terminal or else false
[ -u "$file" ] Return true if file has its Set User ID (SUID) bit set or else false
[ -r "$file" ] Return true if file is readable or else false
[ -w "$file" ] Return true if file is writable or else false
[ -x "$file" ] Return true if file is executable or else false
[ -s "$file" ] Return true if file has size greater than 0 or else false
[ -e "$file" ] Return true if file exists or else false