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 stop a linux job?
What are commands in grammar?
Is cmake a compiler?
What are the commands used in command prompt?
What is $@ in shell?
What command would you use to create an empty file without opening it to edit it?
Who is unix command?
What are bash scripts used for?
What does grep command do?
What does mkdir mean in linux?
What is difference between egrep and grep?
What is difference between sh and bash?
In order to display the last five commands you have entered using the fc command, you would type?
What command used for showing user info like Login Name, Canonical Name, Home Directory,Shell etc..?
Which commands are used to set a processor-intensive job to use less cpu time?