[ubuntu-za] Script error
jonathan at vhata.net
Tue Apr 14 13:46:12 BST 2009
On 14 Apr 2009, at 2:40 PM, Alf Stockton wrote:
> if [ -f /mnt/backup/mailbackups/*.dotproject.backup.sql ]
> rm /mnt/backup/mailbackups/*.dotproject.backup.sql
It has nothing to do with newlines or semicolons: those are
interchangeable in POSIX shells - it's purely a matter of aesthetics,
whether you want to start a newline or put the commands on the same
line separated by semicolons.
If the above works, then I'm guessing you only have one file that
matches that pattern, so the pattern expands to one filename, and the
'-f' test works fine. Or, you don't have any files, so the condition
is failing, and you're carrying on your merry way.
Using '-f' is not a magic recipe for "please tell me if this stuff
exists" - it is a very explicit call that takes one filename parameter
and returns true if the filename exists and is a regular file, and
returns false otherwise. So, supplying it with a pattern is going to
give a syntax error if the pattern expands to more than one file,
because the function only takes one parameter.
More information about the ubuntu-za