Code In Tech - The Ultimate World of Computer Technology

Saturday 12 May 2012

Shell script to find the length of string, if it’s greater than 10 then print string is greater than 10 else less than 10.

SOURCE CODE:

echo “Enter the string:“
read str
l =`expr length $str`
if [ $l –lt 10 ]
then
     echo “String is less than 10”
fi
if [ $l –eq 10 ]
then
     echo “String is equal to 10”
fi

if [ $l – gt 10 ]
then
     echo “String is reater than 10”
fi

OUTPUT:

Enter the string:
123456789181 

No comments :

Post a Comment