Today we will look into an example of testing file existence using if then else
Example of if then
Code:
# bash conditional test if file exists
if [ -f /home/devopsrun/myfile.txt ]
then
echo "/home/devopsrun/myfile.txt exists."
fi
Example of if then else
Code:
# bash conditional test if file exists
if [ -f /home/devopsrun/myfile.txt ]
then
echo "/home/devopsrun/myfile.txt exists."
else
echo "/home/devopsrun/myfile.txt DOES NOT exist."
fi