From 6479b266568f630b5cd9379e5e7b3257aec56769 Mon Sep 17 00:00:00 2001 From: bonnie ng Date: Thu, 29 Aug 2024 18:14:01 +0000 Subject: [PATCH] fix command for #Check if a variable is null --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7c91e64..fd5a41a 100644 --- a/README.md +++ b/README.md @@ -1052,9 +1052,10 @@ else echo >&2 "Fatal error. This script requires mydir." fi -# if variable is null -if [ ! -s "$myvariable" ]; then echo -e "variable is null!" ; fi -# True of the length if "STRING" is zero. +# Check if a variable is null +if [ -z "$var" ]; then echo "NULL"; else echo "Not NULL"; fi +# or +[ -z "$var" ] && echo "NULL" # 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