suppress shell script error messages

前端 未结 6 1265
深忆病人
深忆病人 2020-12-24 10:30

In my shell script I got these lines:

rm tempfl.txt
rm tempfl2.txt

If these do not exist I get the error messages:

rm: temp         


        
6条回答
  •  生来不讨喜
    2020-12-24 11:17

    Try this command:

    rm -f tempfl.txt
    

    the -f option acts like this:

    -f, --force  ignore nonexistent files, never prompt
    

    The command also doesn't report a non-zero error code in case the file doesn't exist.

提交回复
热议问题