Need help with a shell script

sandpilot

Registered
Hello all-

I have a situation where I need to run a shell script on login. I have never really written any shell scripts to speak of, and now this one has become a bit of an emergency to get running. This is the basic script that i'm using now:

#!/bin/zsh

/bin/rm /Applications/DTApps/errorlog.txt

It works just fine, but I need it to be conditional, that is check if the file exisit first, if so get rid of it, if not exit the script.

I believe that this should be fairly easy to get done if I knew what I was doing!! Can anyone help me with this one, or point me in the right direction to look for the info to get it going quick. Thanks for any help.

John
 
Try this:

Code:
#!/bin/bash

if [ -f /Applications/DTApps/errorlog.txt ]
then
	rm /Applications/DTApps/errorlog.txt
fi

The -f bit checks to see if the file exists, and if it does, the parts between then and fi will be executed.
 
Code:
#!/bin/sh

FILENAME=filetodelete

if [ -f $FILENAME ]; then
       /bin/rm -f $FILENAME
fi

exit 0;
 
Back
Top