Sunday, December 2, 2012

Compare Two Strings And Size Of Strings Shell Script | Shell Programming


Write a shell script  to to run check on strings which includes whether strings are equal or not and whether the size of the strings greater than zero or not.


Compare Two Strings And Size Of Strings Shell Script |  Shell Programming


Accept Two Strings from User on Terminal then first check Strings whether given string empty or not using [ -z $stringname ] it will return 1 if strings are empty after that we can compare this two strings using = operator .




#!/bin/bash
#Program to check String Related Operations
#Program From Nullpointer.in
echo "Enter First String"
read strf
echo "Enter Second String"
read strs
if [ -z $strf ] || [ -z $strs ]; then
echo "Strings Should Not be Empty...!!!!" 
elif [ "$strf" = "$strs" ]; then
echo "Given Strings are Same....!!!!"
else
echo "Given String are Not Equal....!!!"
fi

0 comments:

Post a Comment