I cannot for the life of me figure this out. It was all running fine until i added another while loop for the directory part, same as the first one. Then i removed the loop and started getting this error.
syntax error near unexpected token `fi'
I have an assignment to write a script to where the user specifies a file to copy then a directory to copy it to, if the directory doesnt exist create it.
the code is:
while [ -z $file ]
echo "Please enter the name of the file you want to copy: "
if [ -f $file ]
echo "Enter the directory you want to copy the file to:"
elif [ ! -f $file ]
echo "$file does not exist. Please run the script again and enter a valid filename"
if [ -d $subdirectory ]
cp $file $subdirectory
When i run it with bash -x
it goes down to entering the directory
+ echo 'Enter the directory you want to copy the file to:'
Enter the directory you want to copy the file to:
+ read subdirectory
then i get
./assignment1.sh: line 42: syntax error near unexpected token `fi'
./assignment1.sh: line 42: `fi'
after i enter a directory
Starting to get panicky now, i have changed things around to no avail, i cannot understand what is wrong. Have to have the assignment done for saturday unfortunately.
Anyway thanks in advance for any help forthcoming :D :D