-1

A syntax error appears at line 49 on the lone else when this script is run. Can anyone point to why? Won't let me run my script. My remove script code and what my script is supposed to have are below:

  • Script must test rm commands and display same error messages as rm command

  • Script name is remove. Create a "deleted" recycle bin directory in your script.

  • Create a hidden file called .restore.info in $HOME. Each line of this file will contain the name of the file in the deleted directory, followed by a colon, followed by the original full path of the file

  • Filenames in the deleted directory will be in the format "filename_inode"

  • Ensure the script can delete multiple files and wildcards

  • Test for the command line argument of -i (interactive) and -v (verbose)

  1 #/bin/bash
  2
  3 function directory(){
  4 if [ ! -d ~/deleted }
  5     then
  6         mkdir ~/deleted
  7 fi
  8 if [ ! -f ~/.restore.info ]
  9     then
 10         touch ~/.restore.info
 11 fi
 12 }
 13
 14 function movefile(){
 15 mv $1 ~/deleted/$1
 16 echo "file moved to recycle bin"
 17 }
 18
 19 function error_conditions(){
 20 #prints error messages and checks if file is in project directory
 21 if [ ! -f ~/project ]
 22     then
 23         echo "cannot remove $filename: no such file or directory"
 24 elif [ -d ~/project ]
 25         then
 26             echo "cannot remove $filename: is a directory"
 27 else
 28     echo "missing operand"
 29 fi
 30 }
 31
 32 function delete_file(){
 33 #gets inode for filename
 34 inode=$(stat -c%i $filename)
 35 filename=$1
 36 pwd=$(readlink -e$filename)
 37 if $interactive
 38     then
 39         if [ $verbose = true ]; then
 40             read -p "Are you sure you want to delete $filename?" i_input
 41                 if [ $i_input == "y" ] || [ $i_input == "Y" }  
 42                     then
 43                 mv $filename ~/delete/${filename}_inode
 44                 echo ${filename}_$inode:$pwd>>~/.restore.info
 45                 echo "$filename has been deleted"
 46                     else
 47                     echo "Nothing has been deleted"
 48                 fi
 49         else
 50             read -p "Are you sure you want to delete $filename?" i_input
 51             if [$i_input == "y" ] || [ $i_input == "Y" ];
 52                 then
 53                 mv $filename ~/deleted/${filename}_$inode
 54                 echo ${filename}_$inode:$pwd>>~/.restore.info
 55                     else
 56                     echo Aborted
 57             fi
 58         fi
 59     elif $verbose
 60         then
 61             mv $filename ~/deleted/${filename}_inode
 62             echo ${filename}_$inode:$inode:pwd>>~/.restore.info
 63             echo "$filename has been deleted."
 64     else
 65         mv $filename ~/deleted/${filename}_$inode
 66         echo ${filename}_$inode:$pwd>>~/.restore.info
 67         echo Executed
 68 fi
 69 }
 70 interactive=false
 71 verbose=false
 72 recursive=false
 73 while getopts iv option
 74 do
 75     case $option in
 76         i) interactive=true;;
 77         v) verbose=true;;
 78     esac
 79 done
 80 shift $[OPTIND-1]
 81 for i in $*
 82     do
 83 filename=$i
 84 baseline=$(basename $i)
 85 if [ "$i" == "" ];
 86     then
 87         echo "No filename provided"
 88     elif [ -d $filename ];
 89         then
 90             if [ ! $recursive = true ];
 91                 then
 92                     echo "Directory name provided, please provide a file"
 93             fi
 94     elif [ ! -f $filename ];
 95         then
 96             echo "File does not exist"
 97     elif [ "$basefule" == "safe_rm" ]
 98         then
 99             echo "Attempting to delete safe_rm"
100     else
101         delete_file $filename
102     fi
103     done
104
105 #################################M A I N###############################
106 directory
107 error_conditions $*
108 delete_file $*
109 move_file $r

closed as off-topic by roaima, muru, mosvy, dr01, GAD3R May 23 at 21:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – muru, mosvy, dr01, GAD3R
If this question can be reworded to fit the rules in the help center, please edit the question.

3

Line 41 has a wrong close bracket

Not the answer you're looking for? Browse other questions tagged or ask your own question.