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 echo
s the correct number of occurrences of t
in var
, but when the character is comma or semicolon, it prints out zero:
var = "text,text,text,text"
num = `expr match $var [,]`
echo "$num"