How do display error messages instantly when command fails?
Answer Posted / ajit mohan b
Suppose you are trying to cat a non existing file:
cat /etc/shado 2>/dev/null || echo “Failed to open file”
command 2 "echo" is executed only if command 1 "cat" returns
a non-zero exit status
# cat /etc/shado 2>/dev/null || echo "Failed to open file"
Failed to open file
#
| Is This Answer Correct ? | 6 Yes | 2 No |
Post New Answer View All Answers
How do I clear my run history?
What is mkdir p linux?
What does (cd dir && command) do?
What is difference between sh and bash?
What is FC command?
How often do you use grep command and how in Linux operating system?
Why we use pwd command in linux?
How do I check my system performance?
What are linux commands useful?
If the programmer wishes to execute an instruction at the specified time. Which command is used?
Which command will show you free/used memory?
what is the roles and responsibilities in linux system admin having 2yrs exp..?
Suppose I lost a root password and I need to give it, I treid to change it through single usermode even though I am not get a password, then what is the otherprocedure to give a root password?
How many types of commands are there in linux?
What is phony in makefile?