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...
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.
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"
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.
Just test if the variable is empty:
if [ -z "$lastUpdated" ]; then
# not set
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With