You're missing ;
s. The general syntax if you put it all in one line would be:
if thing ; then ... ; else ... ; fi
The thing
can be pretty much anything that returns an exit code. The then
branch is taken if that thing
returns 0, the else
branch otherwise.
[
isn't syntax, it's the test
program (check out ls /bin/[
, it actually exists, man test
for the docs – although can also have a built-in version with different/additional features.) which is used to test various common conditions on files and variables. (Note that [[
on the other hand is syntax and is handled by your shell, if it supports it).
For your case, you don't want to use test
directly, you want to test something on the remote host. So try something like:
if ssh user@host test -e "$file" ; then ... ; else ... ; fi