Does it work if you change the double quotes to single quotes -- i.e.,
if [ '(' = '(' ]; then echo 1;fi;
EDITED TO ADD: I've just been able to recreate the problem with a Digital UNIX ksh. Single quotes don't work either on this platform, however escaping the brackets does work:
if [ '\(' = '\(' ]; then echo 1;fi;
According to the man page for ksh, it states:
The following characters have a
special meaning to the shell and cause
termination of a word unless
quoted:
; & ( ) | ^ < > <newline> <space> <tab>
...and goes on to define more parsing rules. It seems that the ( is being interpreted as a special character even when quoted (oddly), hence the requirement for escaping. If you type "set -x
" at the command line before you try your if, you'll see exactly what the shell is trying to do sent to stderr preceded with a '+' sign, which may help the tracing; e.g.:
$ set -x
$ if [ '(' = '(' ]; then echo 1;fi;
+ [ ( = ( ]
ksh: test: argument expected
$
$ if [ '\(' = '\(' ]; then echo 1;fi;
+ [ \( = \( ]
+ echo 1
1
$
It may be that it depends on the ksh implementation as well -- e.g., ksh-88 vs ksh-93 and later. On Digital UNIX, the implementation is ksh-88.