Bourne/bash shell scripts: string comparison
To determine if the value of a variable ($var) is empty (null):
if [ $var == "" ]
then
echo variable is null
fi
To determine if the value of a variable is not empty:
if [ $var != "" ]
then
echo variable is not null
fi
To compare the contents of a variable to a fixed string:
if [ $var == "value" ]
then
echo is the same
fi
To determine if variable’s contents are not equal to a fixed string:
if [ $var != "value" ]
then
echo not the same
fi






Add New Comment
Viewing 4 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment