samedi 31 juillet 2021

Nested else statement on bash script

For some reason, the first else statement is throwing a syntax error and I don't know why

#! /usr/bin/bash
    clear
    read -p "Enter the file you want to append the date to" FILENAME

if [ -f $FILENAME ]
then
    if [ -w $FILENAME ]
        echo "`date +"%d-%m-%Y"`" >> $FILENAME
    else    # FOR SOME REASON THIS ELSE STATEMENT IS THROWING AN ERROR
        echo "$FILENAME cannot be written to"
    fi
    
else
    touch $FILENAME
    echo "`date +"%d-%m-%Y"`" >> $FILENAME
fi 

Aucun commentaire:

Enregistrer un commentaire