I need to count the number of occurrences of a char in a string using Bash.
In the following example, when the char is (for example) t, it
t
I Would suggest the following:
var="any given string" N=${#var} G=${var//g/} G=${#G} (( G = N - G )) echo "$G"
No call to any other program