you can for example remove all other chars and count the whats remains, like:
var="text,text,text,text"
res="${var//[^,]}"
echo "$res"
echo "${#res}"
will print
,,,
3
or
tr -dc ',' <<<"$var" | awk '{ print length; }'
or
tr -dc ',' <<<"$var" | wc -c #works, but i don't like wc.. ;)
or
awk -F, '{print NF-1}' <<<"$var"
or
grep -o ',' <<<"$var" | grep -c .
or
perl -nle 'print s/,//g' <<<"$var"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…