Monday, 2 April 2018

Shell script to count the vowels in the given string

#script to count the number of vowels in the given string
echo "enter a string"
read str
count=0
len=${#str}
while [ $len -gt 0 ]
do
       ch=`echo "$str" | cut -c $len`
       case $ch in
               [aA] | [eE] | [iI] | [oO] | [uU] ) count=`expr $count + 1`;;
       esac
       len=`expr $len - 1`
done
echo "The number of vowels in the given string '$str' is $count"



OUTPUT
Safi>sh vowcnt.sh
enter a string
Aeroplane
The number of vowels in the given string 'Aeroplane' is 5

No comments:

Post a Comment