I'm currently learning Unix and have come across a question in a book that I'm trying to solve.
I'm trying to write a script that asks a user to enter a file name. Then, the script needs to check for file existence. If the file does not exist, that script should display an error message and then exit the script. If the file exists, the script should ask if the user wants to delete the file:
- If the answer is yes or y, the script should remove the file.
- If the answer is no or n, the script should exit from the script.
- If the answer is neither yes nor no, the script should display an error message and exit from the script.
This what I have written so far but have come across with a few errors:
#!/bin/bash
file=$1
if [ -f $file ];
then
echo read -p "File $file existes,do you want to delete y/n" delete
case $delete in
n)
exit
y) rm $file echo "file deleted";;
else
echo "fie $file does not exist"
exit
fi
If anyone come explain where I have gone wrong it would be greatly appreciated