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
Which command will show you free/used memory?
What does grep grep do?
What are the mv command options?
can any one send me one project on linux ...?
You want to know how many lines in the kickoff file contains ‘prize’. Which of the following commands will produce the desired results?
What is the ipconfig command for linux?
Which of the commands will replace all occurrences of the word rate with the word speed in the file racing?
What are the linux commands used in devops?
What would be the result of the command paste -s dog cat?
What is #!/ Bin sh?
What is filter command in unix?
What are the commands used in command prompt?
What command used for showing user info like Login Name, Canonical Name, Home Directory,Shell etc in Linux?
What is build process?
What is the difference between find and locate command in linux?