Showing posts with label Finding the length of a string. Show all posts
Showing posts with label Finding the length of a string. Show all posts

Monday, 20 July 2020

Shell script to accept a string from the terminal and echo a suitable message if it doesn’t have at least 10 characters.


Program
echo "enter the string"
read str
Len=`expr  "$str" :  '.*'`
if test $Len -lt 10
then
     echo " $str has less than 10 characters"
else
echo  " the input string is \"$str\" "
fi


OUTPUT
enter the string
welcome to the world of UNIX
 the input string is "welcome to the world of UNIX"

enter the string
jhhj
 jhhj has less than 10 characters