Error:

Check if file or directory exists

if [[ -e /etc/passd ]]; then
    echo exists
fi

Check if file exists and is a block device

if [[ -b /dev/sda1 ]]; then
    echo "block device"
fi

Check if file exists and is a character device

if [[ -c /dev/sda1 ]]; then
    echo "char device"
fi

Check if path exists and is a directory

if [[ -d /etc ]]; then
    echo "is a directory"
fi

Check if file exists and is a regular file

if [[ -f /etc/passwd ]]; then
    echo "is a regular file"
fi

Check if file exists and has sgid set

if [[ -g /etc/passwd ]]; then
    echo "sgid is set"
fi

Check if file exists and is a symbolic link

if [[ -h /etc/passwd ]]; then
    echo "is symlink"
fi

Check if file exists and has sticky bit set

if [[ -k /etc/passwd ]]; then
    echo "sticky bit set"
fi

Check if file exists and is a named pipe

if [[ -p /etc/passwd ]]; then
    echo "named pipe"
fi

Check if file exists and is readable

if [[ -r /etc/passwd ]]; then
    echo "readable"
fi

Check if file exists its size is greater than zero

if [[ -s /etc/passwd ]]; then
    echo "not empty"
fi

Check if file descriptor is open and refers to terminal

if [[ -t 1 ]]; then
    echo "stdout is terminal"
fi

Check if file exists and has suid bit set

if [[ -u /path/to/file ]]; then
    echo "SUID is set"
fi

Check if file exists and is writable

if [[ -w /path/to/file ]]; then
    echo "writable"
fi

Check if file exists and is executable

if [[ -x /path/to/file ]]; then
    echo "executable"
fi

Check if file exists and is owned by the effective group id

if [[ -G /path/to/file ]]; then
    echo "gid match"
fi

Check if file exists and is owned by the effective user id

if [[ -O /path/to/file ]]; then
    echo "uid match"
fi

Check if file exists and has been modified since it was lat read

if [[ -O /path/to/file ]]; then
    echo "has been modified"
fi

Check if file exists and is a socket

if [[ -S /path/to/file ]]; then
    echo "is a socket"
fi

Check if files refer to the same device and inode

if [[ /path/to/file1 -ef /path/to/file2 ]]; then
    echo "file1 and file2 are the same file"
fi

Check if one file is newer than another file

# True if file1 is newer (according  to  modification  date)  
# than file2, or if file1 exists and file2 does not.
if [[ /path/to/file1 -nt /path/to/file2 ]]; then
    echo "file1 modififcatin date is more recent"
fi

Check if one file is older than another file

 #True  if file1 is older than file2, or if file2 
# exists and file1 does not.
if [[ /path/to/file1 -ot /path/to/file2 ]]; then
    echo "file2 modififcatin date is more recent"
fi

Check if shell option is enabled

# echo $SHELLOPTS to see enabled options
if [[ -o xtrace ]]; then
    echo "Debug is enabled"
fi

Check if variable is set (bash 4)

if [[ -v var1 ]]; then
    echo "var1 is set";
fi

Check if string is empty

if [[ -z "$str" ]]; then 
    echo "str is empty";
fi

Compare two strings

# quotes for strict compare
if [[ "$str1" = "foo" ]]; then
    echo "bar"
fi

# glob matching
if [[ "$str" = *.txt ]]; then
    echo "txt file"
fi 

if [[ "$str1" != "foo" ]]; then
    echo "!bar"
fi 

if [[ "$str1"  < "foo" ]]; then
    echo "str1 sorts before foo"
fi 

Check if string matches glob

if [[ "$str" = *.txt ]]; then
    echo "txt file"
fi 

Compare two integers

# a == 10
if [[ $a  -eq 10 ]]; then .. ; fi

# a != 10
if [[ $a  -ne 10 ]]; then .. ; fi

# a < 10
if [[ $a  -lt 10 ]]; then .. ; fi

# a <= 10
if [[ $a  -lte 10 ]]; then .. ; fi

# a > 10
if [[ $a  -gt 10 ]]; then .. ; fi

# a >= 10
if [[ $a  -ge 10 ]]; then .. ; fi

Check if string is a number

case $var in
    ''|*[!0-9]*) echo not number ;;
    *) echo number ;;
esac

Check if string matches regexp

if [[ "$var" =~ ^[0-9] ]]; then
    echo "starts with digit"
fi