Keep in mind that the bash [
built-in command must honor the syntax requirements of the external /bin/[
command (usually a link to /bin/test
) in order to maintain backward compatibility with the archaic versions of sh in which test
([
) was NOT internal to the shell.
In order to honor that level of compatibility the parser must treat || as a separator to a new command, thus terminating the [
command. When /bin/test
is called as [
(it checks its on argv[0]) then it requires the closing "]" as a parameter.
Use -o (or) in your test ([
) commands.
(Personally I think it's a bad idea do use the [
form of test
for exactly this reason. Novices will think of it as a syntactic feature ... a sort of conditional expression construct to the if
statement, expecting semantics which are not consistent with its implementation as command. So I teach it as test
even though I use it (sometimes) as [
because the practice is so widespread.