Quote:
if [ cat /var/run/damon ]
then rm /var/run/damon
|
yea, this is a confusing issue. the if operator in bash checks the return value of the command following it. the [ ] part is actually a command. now, i'm not an expert on the history here or anything, but basically the command is called test, and [ is an abbreviation of it. bash may have a build in [ ] operator by now, but at any rate, the functionality is the same.
for the case above to work, you would need to remove the []'s
Code:
if cat /var/run/damon
then
rm /var/run/damon
this relies on the cat command returning 0 if the file you are trying to cat exists. what you probably would rather do is
Code:
if [ -e /var/run/damon ]
then
rm /var/run/damon
which will actually do the same thing as
Code:
if test -e /var/run/damon
then
rm /var/run/damon
the test command, or [ for short, is checking if the file exists, and will return 0 if it does (which is the unix "there were no errors" return code)