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
Building on everyone's great answers and comments, this is the shortest and sweetest version:
grep -o "$needle" <<< "$haystack" | wc -l