Custom Search

Tuesday, 8 May 2012

Write a Linux shell script for comparison between two strings whether both the strings are equal or not, Unix program for comparison between two strings


Write a Linux shell script for comparison between two strings whether both the strings are equal or not, Unix program for comparison between two strings


Program
clear
echo"Enter String 1:"
read str1


echo"Enter String 2:"
read str2


s1='expr$str1|wc-c'
s1='expr$s1-1'


s2='expr$str2|wc-c'
s2='expr$s2-1'


flag=0


if[$s1-ne$s2]
then
 echo"Strings are different"
else
 for((i=1;i<=s1;i++))
 do
  sc1='expr$str1|cut-c$i'
  sc2='expr$str2|cut-c$i'


  if[$sc1!=$sc2]
  then
       flag=1
       break
  fi
 done


if[ $flag-eq 0]
then
  echo"String are equal"
else
 echo"Strings are different"
fi
fi


Output:
Enter string 1: Maulik
Enter string 2: Dantara
Strings are different.

<<< Previous  ||  Current  ||  Next >>>  

No comments:

Post a Comment

Laptops