#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
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