Answers for "shell if "-z""

4

if -z in bash

The -z flag causes test to check whether a string is empty. 
Returns true if the string is empty, false if it contains something.
Posted by: Guest on July-26-2021
0

shell if "-z"

# Returns true if string empty.
# E.G: file.txt does not exist

EXISTS=$(cat file.txt 2> /dev/null)

if [ -z "${EXISTS}" ]; then
	echo "Does not exist"
else
    echo "Exist!"
fi

# Output: 
# Does not exist
Posted by: Guest on January-14-2022

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language