suppress shell script error messages

前端 未结 6 1295
深忆病人
深忆病人 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:18

    You have two options:

    Suppress rm warnings

    $ rm tempfl.txt 2> /dev/null
    

    Redirect script output to /dev/null

    $ ./myscript.sh 2> /dev/null
    

    The latter has a drawback of missing all other warning messages produced by your script.

提交回复
热议问题