Bash:Test
Jump to navigation
Jump to search
The test command evaluates an expression and sets $?
- 0 => True/Successful
- 1 => False/Unsuccessful
In if statements test can be executed as [ expression ]. This has better readability.
- if [ x${var} = x ]
- Test if var is empty
- -f filename
- Regular file existence
- -e filename
- Any file existence
- -s filename
- File is bigger than 0 bytes
- -z "string"
- String is zero-length
- -n "string"
- String is not zero-length