Shell Script to Compare Two Strings on Command Line Full Tutorial For Beginners

 

 

string.sh

 

 

#shell script to compare two strings
  
read -p "Enter two strings: " str1 str2

if [ $str1 == $str2 ]
then
    echo "Equal"
else
    echo "Un Equal"
fi

 

 

read -p "Enter a string: " str1
  
if [ $str1 == "linux" ]
then
    echo "linux"
elif [ $str1 == "unix" ]
then
    echo "unix"
else
    echo "Neither linux nor unix"
fi

Leave a Reply