Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

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
 
PREVIOUS NEXT
Tagged: #shell
ADD COMMENT
Topic
Name
9+1 =