Why error handling prevents silent failures
📖 Scenario: You are writing a small script to copy files and then delete the original files. You want to make sure the script tells you if something goes wrong, so you don't lose files silently.
🎯 Goal: Build a bash script that copies a file, checks if the copy succeeded, and only then deletes the original file. You will add error handling to prevent silent failures.
📋 What You'll Learn
Create a variable with the source file name
Create a variable with the destination file name
Copy the source file to the destination
Check if the copy command succeeded using
$?If the copy succeeded, delete the source file
If the copy failed, print an error message
Print a success message if the file was copied and deleted
💡 Why This Matters
🌍 Real World
Scripts that copy or move files must confirm success to avoid losing data silently. Error handling helps catch problems early.
💼 Career
System administrators and DevOps engineers write scripts that automate file management. Knowing error handling prevents costly mistakes.
Progress0 / 4 steps