When you are writing a shell script, there are scenarios like, you want to check if a file exists and perform an action based on that .
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