Simple bash if then else example

if [ -r somefile ]; then 
   content=$(cat somefile) 
elif [ -f somefile ]; then 
   echo "The file 'somefile' exists but is not readable to the script." 
   echo "The file 'somefile' does not exist." 

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me or _justin_kelly

Leave a comment

Notify me of replies by email.