File existence checks
📖 Scenario: You are writing a simple script to check if certain files exist on your computer. This is useful when you want to make sure important files are present before running other commands.
🎯 Goal: Create a bash script that checks if a file named data.txt exists in the current folder and prints a message based on the result.
📋 What You'll Learn
Create a variable called
filename with the value data.txtCreate a variable called
filepath that stores the full path to the file using $(pwd) and filenameUse an
if statement with the -e test to check if the file exists at filepathPrint
File exists. if the file is foundPrint
File does not exist. if the file is not found💡 Why This Matters
🌍 Real World
Checking if files exist is a common task in automation scripts to avoid errors when processing files.
💼 Career
Many IT and DevOps roles require writing scripts that verify file presence before running backups, deployments, or data processing.
Progress0 / 4 steps