I'm trying to put an if statement within an if statement. It seems to work until the last echo command in the script which doesn't print.
For testing I have created a directory with the same name as the $foldername which is input via a prompt. I am inputting this during the execution of the script. During the running of the script I am choosing the option to overwrite the directory, which works fine. However, I am confused as to why after the folder has been replaced, the script doesn't then move onto the last echo statement:
echo "Folder $foldername has now been created"
This is not being printed on screen which suggest the script isn't exiting the if statement section. Any ideas why?
#!/bin/bash echo "Please input the folder name you would like to create then press ENTER" read foldername if [ -d "/home/location/test_directories/$foldername" ] then echo "$foldername already exists" sleep 2 echo echo echo "Do you want to overwrite this folder and start afresh?" read -p "Type Y overwrite the folder, or N to exit the script" -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] then echo "You have chosen to overwrite the folder $foldername" rm -rf /home/location/test_directories/$foldername; mkdir /home/location/test_directories/$foldername sleep 2 else exit fi exit else mkdir /home/location/test_directories/$foldername fi sleep 2 echo "Folder $foldername has now been created"