Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash If statement null

Looking for the correct syntax that looks at a bash variable and determines if its null, if it is then do ... otherwise continue on.

Perhaps something like if [ $lastUpdated = null?; then... else...

like image 828
Tony Avatar asked Oct 03 '13 13:10

Tony


People also ask

Is there a null in bash?

The Bash null command, represented by a colon : , is also known as the POSIX shell colon command. This command has no effect and does absolutely nothing, hence the null command terminology.

How do I check if an argument is empty in bash?

To find out if a bash variable is empty: Return true if a bash variable is unset or set to the empty string: if [ -z "$var" ]; Another option: [ -z "$var" ] && echo "Empty" Determine if a bash variable is empty: [[ ! -z "$var" ]] && echo "Not empty" || echo "Empty"

What is bash if [- N?

A null string in Bash can be declared by equalizing a variable to “”. Then we have an “if” statement followed by the “-n” flag, which returns true if a string is not null. We have used this flag to test our string “name,” which is null.


1 Answers

Just test if the variable is empty:

if [ -z "$lastUpdated" ]; then
    # not set
fi
like image 197
trojanfoe Avatar answered Sep 22 '22 03:09

trojanfoe