It seems you've read up quite a few things about the if test in bash. So I'm going to give you a slightly advanced answer.
only looks at the exit status of the test
is simply an alias for test
, as you probably knew already).
As you probably already know, other programs also have exit statuses. if
can use these the same way it uses the exit status of test
The real problem you are facing, is that test
now gets fed a commandline like this:
test -e path/to/my/pictures/20090101 path/to/my/pictures/20090102 path/to/my/pictures/20090103 path/to/my/pictures/20090114
It only expects one filename after the -e argument, so the other filenames are confusing test
. It sees more than one filename, so it says it wants an operator that can handle 2 arguments (-e is an operator that can handle 1 argument).
An operator that can handle 2 arguments is a binary operator, binary refers to "has 2 sides", not "is made up of 1s an 0s".
Now the problem is understood, the solution.
is a command that can accept multiple filenames. If it cannot find any files, it exits with exit status 2, if it can it exits with exit status 0. So if
can be used together with ls
to find out if there is any number of files with that name-pattern.
so this should work:
if ls path/to/my/pictures/200901*
This outputs error messages and a list of your files, if applicable. You probably don't want that in your script.
Also, this is quite unreadable for people who aren't used to using if
, the variable with the last command's exit status, is more common.
This suppresses the output of ls and uses $?
ls dinge > /dev/null 2>&1
if [ $? -eq 0 ]
is a binary operator, it looks at the things on its left and on its right