suppress shell script error messages
问题 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: tempfl2.txt: No such file or directory rm: tempfl.txt: No such file or directory Is there a way to only suppress these messages even though they do not always appear, as the files might exist? 回答1: 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