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


Please Help Members By Posting Answers For Below Questions

Which command will show you free/used memory?

734


What does grep grep do?

690


What are the mv command options?

637


can any one send me one project on linux ...?

2543


You want to know how many lines in the kickoff file contains ‘prize’. Which of the following commands will produce the desired results?

754


What is the ipconfig command for linux?

710


Which of the commands will replace all occurrences of the word rate with the word speed in the file racing?

710


What are the linux commands used in devops?

735


What would be the result of the command paste -s dog cat?

728


What is #!/ Bin sh?

716


What is filter command in unix?

733


What are the commands used in command prompt?

721


What command used for showing user info like Login Name, Canonical Name, Home Directory,Shell etc in Linux?

790


What is build process?

730


What is the difference between find and locate command in linux?

732