From 964a5394538e612a26474111dcad08d7f689249a Mon Sep 17 00:00:00 2001 From: Deniss Samcuks Date: Fri, 9 May 2025 16:14:32 +0300 Subject: [PATCH] [bash/en] Added -z and -n string conditional operators (#5307) * Added -z and -n string conditional operators * Fix typo --- bash.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bash.md b/bash.md index 50680abb..6ce1734e 100644 --- a/bash.md +++ b/bash.md @@ -175,6 +175,12 @@ fi if [[ "$name" == "Daniya" ]] || [[ "$name" == "Zach" ]]; then echo "This will run if $name is Daniya OR Zach." fi + +# To check if a string is empty or not set use -z and -n to check if it is NOT empty +if [[ -z "$name" ]]; then + echo "Name is unset" +fi + # There are other comparison operators for numbers listed below: # -ne - not equal # -lt - less than