In the old single-bracket test, >
are treated as redirections, and you have to first backslash escape them to \>
, at which point they become greater-than/less-than operators. The newer double-bracket test does not treat them as redirectors, so the unescaped values are greater-than/less-than, and escaping or quoting them makes them literal.
Note that these are string, not integer comparisons.
When using the regex operator in "[[
", it's often better to store the expression in a separate variable first. Then you don't have to worry about escaping anything inside the test construct itself.
if [[ $s1 =~ $re ]]
Be sure not
to quote the regex variable here, or else it will be treated as a string of literal characters.
In this particular instance though, you can also use a simple glob, like so.
if [[ $s1 == '>'* ]]
Notice again how you can quote/escape the character(s) that need to be matched literally, but be careful to leave the actual globbing character(s) unescaped.