mirror of
https://github.com/onceupon/Bash-Oneliner.git
synced 2024-11-21 20:37:00 +00:00
fix command for #Check if a variable is null
This commit is contained in:
parent
7cfb4e286c
commit
6479b26656
@ -1052,9 +1052,10 @@ else
|
|||||||
echo >&2 "Fatal error. This script requires mydir."
|
echo >&2 "Fatal error. This script requires mydir."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if variable is null
|
# Check if a variable is null
|
||||||
if [ ! -s "$myvariable" ]; then echo -e "variable is null!" ; fi
|
if [ -z "$var" ]; then echo "NULL"; else echo "Not NULL"; fi
|
||||||
# True of the length if "STRING" is zero.
|
# or
|
||||||
|
[ -z "$var" ] && echo "NULL"
|
||||||
|
|
||||||
# Using test command (same as []), to test if the length of variable is nonzero
|
# Using test command (same as []), to test if the length of variable is nonzero
|
||||||
test -n "$myvariable" && echo myvariable is "$myvariable" || echo myvariable is not set
|
test -n "$myvariable" && echo myvariable is "$myvariable" || echo myvariable is not set
|
||||||
|
Loading…
Reference in New Issue
Block a user