How to get rid of cannot remove file error in bash script?

Hi Guys,

I am creating a couple of temp. files in a script. After completing the script, I am using the rm command to delete these files. The files are getting deleted but I am getting "filename - cannot find file;no such file or directory" error in my bash shell terminal window.

I am using the following command to remove the files:

rm /cygdrive/c/test *.txt
rm /cygdrive/c/test *.dat

How can I get rid of this error on the bash terminal? Can I suppress error outputs in my bash script?

Thanks.

Why do you have space in your rm command?

Yes, I do.

It is removing the files, I just want to get rid of the error output to the terminal.

The rm command can handle multiple files on the command line. For example, you can tell it to remove 1.txt and 2.txt with

rm 1.txt 2.txt

Your code has spaces between "test" and the wildcard "*" so rm is trying to remove two different things, just like it would remove 1.txt and 2.txt in my example. In this case, it's trying to remove /cygdrive/c/test, and *.txt (all .txt files in the current directory). This is what you need to use instead:

rm /cygdrive/c/test/*.txt
rm /cygdrive/c/test/*.dat