[ubuntu-za] Script error
Jonathan Hitchcock
jonathan at vhata.net
Tue Apr 14 13:46:12 BST 2009
Hi,
On 14 Apr 2009, at 2:40 PM, Alf Stockton wrote:
> if [ -f /mnt/backup/mailbackups/*.dotproject.backup.sql ]
> then
> rm /mnt/backup/mailbackups/*.dotproject.backup.sql
> fi
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
mailing list