I wanted to make a shell script that accepts a vowel and prints the number of occurrences of that vowel inside the text file "abc.txt".
The following script works perfectly (a script to print the number of occurrences of the vowel "a" inside the text file "abc.txt"):
#!/bin/bash
grep -o [aA] abc.txt|wc -l
But I want to implement this for all the vowels so I did this:
#!/bin/bash
echo -n "Enter the desired vowel: "
read ch
case ch in
a) grep -o [aA] abc.txt|wc -l;;
A) grep -o [aA] abc.txt|wc -l;;
e) grep -o [eE] abc.txt|wc -l;;
.
.
.
U) grep -o [uU] abc.txt|wc -l;;
esac
The code executes but after I enter the desired vowel nothing is displayed. I've also tried this (but the results are the same as those of the code above):
#!/bin/bash
x=0
echo -n "Enter the desired vowel: "
read ch
case ch in
a) x=grep -o [aA] abc.txt|wc -l;echo $x;;
A) x=grep -o [aA] abc.txt|wc -l;echo $x;;
e) x=grep -o [eE] abc.txt|wc -l;echo $x;;
.
.
.
U) x=grep -o [uU] abc.txt|wc -l;echo $x;;
esac
I'm lost as to why the grep statements aren't displaying anything when I put them inside a case statement.