Nobody explained the error yet.
if [1==2] then echo "y" fi;
The first line was perfectly valid syntax as far as the shell was concerned. It is of the form:
if cmd args
In this case,
cmd is derived from the expansion of the
[1==2] is a globbing pattern that expands to the list of files in the current directory whose name consist of either a
For instance, if there's a file called
2 in the current directory, that becomes:
if 2 then echo fi;
That is run the
2 command with 4 arguments:
fi, as the first command in the
if part of an
The error comes from that second
; on the second line. You would have had the same error message by entering that
; alone on the command line.
; must be used to separate commands, it cannot be used on its own like that.