Problem Statement
How do you handle errors gracefully in automation scripts?
Explanation
You can check the exit status of each command using $? and use if conditions to act on failures.
Adding set -e at the top stops script execution immediately when a command fails, ensuring predictable automation.
Code Solution
SolutionRead Only
set -e cp data.txt /backup/ || echo 'Backup failed'
Practice Sets
This question appears in the following practice sets: