Skip to content
Advertisement

Stop grep message from posting

I am working on a script that take 1 string argument and a file. I want it so that if a file is put in that doesn’t exist, then it will display the “filename cannot be read” message.

That part does work however it also displays a “grep: grep.txt: No such file or directory” message. Is there any way to stop the grep message from posting and ending the script if the first if statement is true?

JavaScript

Advertisement

Answer

Exit the script with a non-zero exit code to indicate failure and stop it from continuing on to the grep.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement