title: Count occurrences of a char in a string using Bash
body: <p>I need to count the <em>number of occurrences of a char in a string</em> using Bash.</p>
  
  <p>In the following example, when the char is (for example) <code>t</code>, it <em><code>echo</code>s</em> the correct number of occurrences of <code>t</code> in <code>var</code>, but when the character is comma or semicolon, it prints out zero:</p>
  
  <pre><code>var = "text,text,text,text" 
  num = `expr match $var [,]`
  echo "$num"
  </code></pre>