Thursday, December 20, 2012

compare strings in bash shell script

if [ $1 == $2 ] ; then
echo "Equal"
else
echo "not equal"
fi

if [ $1 != $2 ]; then
echo "not equal"
else
echo "equal"
fi


if [ $1 == "test" ] ; then
echo "Equal"
else
echo "not equal"
fi

reference:
http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/

No comments:

Post a Comment