Exclamation Point and Too Many Arguments
<p>I tried to setup a conditional in a bash script but I've run into an unusual error; bash is complaining of too many arguments, but everything seems correct to me:</p>

<pre><code>[ "${foo:0:1}" = '!' -o "$foo" = '*' ]
</code></pre>

<p>Quite simply, the test should succeed if <code>$foo</code> is either an asterisk, or begins with an exclamation point.</p>

<p>However, when <code>$foo</code> begins with an exclamation point, I get the following error in bash:</p>

<pre><code>bash: [: too many arguments
</code></pre>

<p>The weird thing is that it works fine if I omit the second condition like so:</p>

<pre><code>[ "${foo:0:1}" = '!' ]
</code></pre>

<p>So it seems like the <code>"${foo:0:1}"</code> evaluating to an exclamation point is somehow interfering with the logical or condition, can anyone explain what's going on here, and what the best way would be to work around it?</p>

<p>It doesn't seem to matter what I'm testing for, for example:</p>

<pre><code>[ "${foo:0:1}" = 'z' -o "$foo" = '*' ]
</code></pre>

<p>Will still fail if <code>$foo</code> begins with an exclamation point. This has me concerned, as I have numerous scripts that test characters in the same way that could presumably fail unexpectedly if a value contains an exclamation mark, so I could do with finding a good workaround for this.</p>