In Bash at least the following command tests if $var is empty:
if [[ -z "$var" ]]; then
# $var is empty, do what you want
fi
The command man test
is your friend.
More Related Contents:
- While loop stops reading after the first line in Bash
- How can I compare numbers in Bash?
- Pipe output and capture exit status in Bash
- Redirect stderr and stdout in Bash [duplicate]
- Which characters need to be escaped when using Bash?
- How to put a line comment for a multi-line command [duplicate]
- Why does “local” sweep the return code of a command?
- bash : Illegal number
- Batch renaming files with Bash
- Shell redirection i/o order
- How to generate random number in Bash?
- In bash, how do I bind a function key to a command?
- “Invalid Arithmetic Operator” when doing floating-point math in bash
- Using sed to mass rename files
- Colorized grep — viewing the entire file with highlighted matches
- How to pass in password to pg_dump?
- Select random lines from a file
- Variables getting reset after the while read loop that reads from a pipeline
- How to kill all subprocesses of shell?
- Should I use a Shebang with Bash scripts?
- Get current directory or folder name (without the full path)
- Execute a shell function with timeout
- Convert Unix timestamp to a date string
- Using Bash to display a progress indicator (spinner) [duplicate]
- Extract version number from a string
- How do I get both STDOUT and STDERR to go to the terminal and a log file?
- Use GNU find to show only the leaf directories
- Get the name of the caller script in bash script
- docker entrypoint running bash script gets “permission denied”
- What does `kill -0 $pid` in a shell script do?