How to clear a file

Hello,

I have a script which creates a certain text file.
Whenever I call it, I need to recreate this file, because I have no need in the previous content.

So I thought to remove the file every time I call the script, and that way I am sure that the previous content will not interrupt me.

I wrote this:

 
#!/usr/local/bin/tcsh -f
rm file1
rm file2

but then I get this error:

Is there anything else I could do, perhaps there's a command which only clears the file? Or will it print the same error?

Perhaps some of you will think that it prints this error in the times that I call the script in the first time, but sometimes it works and sometimes it doesn't.

Thank,
Shira.

You can:

Check first for the files:

for file in file1 file2 ; do

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

done

Delete 'em and don't care for error messages:

/bin/rm file1 file2 2>/dev/null

Or just initialize them, which is kind of clean and neat:

:>file1
:>file2

It works, thanks so much! :slight_smile: