I am trying to write a shell script which will read a file and counts the number of vowels in the file. The code which read the file is as follows -
while read -n 1 c
do
l=$(echo $c | tr [:upper:] [:lower:])
[[ "$l" == "a" || "$l" == "e" || "$l" == "i" || "$l" == "o" || "$l" == "u" ]] && (( v++ ))
done < $file
When I run the script, getting the error -
read: 22: Illegal option -n where 22 is the line number.
I am confused why -n option is not working in the script whereas read -n 1 c command is working fine from terminal.
Any suggestion is appreciated.
Thanks in advance.