Operator¶
AND and OR¶
No short circuits but &&and || have short circuits
-a: [ -r "$FN" -a ( -f "$FN" -o -p "$FN" ) ]-o: [ -z "$V1" -o -z "${V2:=YIKES}" ]
Comparison operators¶
https://tldp.org/LDP/abs/html/comparison-ops.html
Always put the $var in quotes
-nis not null-zis null - has zero length Using-nwithout quoting, will return true even it's empty==string comparison-eqnumerical comparison
If always use the math-style symbols for comparison:
do numerical tests with the
double-parenthesessyntaxdo string comparisons with the
double-square-bracketssyntax
Arithmetic operators¶
=, +=, -=, *=, /=, &=, \=, ^=, <<=, >>= Integer arithmetic:
File testing unary operators¶
Exists
-d File is a directory
-f File is a regular file
-e File exists
-s File has a size greater than zero
Read/write etc
-r File is readable
-w File is writable
-x File is executable
-N File has been modified since it was last read
Types
-b File is a block special device (for files like /dev/hda1)
-c File is character special (for files like /dev/tty)
-S File is a socket
-p File is a named pipe
-h File is a symbolic link (same as -L )
-L File is a symbolic link (same as -h )
bit set
-k File has its sticky bit set
-u File has its set-user-ID (setuid) bit set
-g File has its set-group-ID (setgid) bit set
-O File is owned by the effective user ID
-G File is owned by the effective group ID