Skip to content

Instantly share code, notes, and snippets.

@slaveofcode
Created April 20, 2021 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaveofcode/0f4d4ec9841e4b49b880d7e8dd1925fc to your computer and use it in GitHub Desktop.
Save slaveofcode/0f4d4ec9841e4b49b880d7e8dd1925fc to your computer and use it in GitHub Desktop.
if conditions for checking variable was set or exist on shell script
#!/bin/sh
a=1
b=2
# #Check whether they are equal
# if [ $a = $b ]
# then
# echo "a is equal to b"
# fi
if [ ! -z "$a" ] && [ ! -z "$b" ];
then
echo "a & b exist"
elif [ ! -z "$a" ]; then
echo "a exist"
elif [ ! -z "$b" ]; then
echo "b exist"
else
echo "a and/or b not exist"
fi
#Check whether they are not equal
# if [ $a != $b ]
# then
# echo "a is not equal to b"
# fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment