[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash Scripting



I'm trying to learn some simple scripting. I'm having trouble trying to switch
from BATch habits to shell techniques.  I am trying to duplicate the IF EXIST
function in a batch file using shell code, and this is what I've come up with,
but it is not working: could somebody help me out please?

#!/bin/sh
clear
if [test -f .cron.var]; then
  echo FILE EXISTS, ERASE IT
  rm .cron.var
else 
  echo FILE DOES NOT EXIST
  echo CREATE THE FILE
  touch .cron.var
fi


This results in the same condition regardless of whether the file exists or
not.  I just want to know if a file exists, if not, create it. If it does,
erase it. Running the script twice should produce both results.

So, what am I missing?  I've looked thorough man test, I'm sure I'm missing
something there. I tried www.ugu.com and the scripting pages there, but they
aren't helping much either.  Any advice would be greatly appreciated.  Thanks!

Jason

P.S.  was that Novice list at novice@kalamazoolinux.org?