Delete restore and empty trash

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

A set of Linux shell scripts is required to allow users to �remove' files without them really disappearing until the �dustbin' is emptied. The three shell scripts required are :-

del <filename> - This script should move the file called <filename> (a full or relative pathname) to the
dustbin directory.

trash [-a] - This script should remove the contents of the dustbin directory.
If the -a option is not used, the script should print the filenames in the dustbin one by one and ask the
user for confirmation that they should be deleted.
Otherwise, If the -a option is used, the script should simply remove ALL files from the dustbin.

restore [-n] <filename> - This script should move the file called <filename> (a full or relative pathname)
back to its original directory.
If the -n option is used, the script should allow the file to be moved to a directory nominated by the user.

  1. Relevant commands, code, scripts, algorithms:

bash code
using ubuntu
I used a dustbin directory to keep my deleted files

  1. The attempts at a solution (include all code and scripts):

del script

#!/bin/bash
echo "Do you want to delete this file?"
echo "Y/N"
read ans
case "$ans" in
  Y) echo "`readlink -f $1`" >>/home/ian/store & mv $1 /home/ian/dustbin ;;
  N) echo "File not deleted" ;;
esac

trash script

#!/bin/bash

if ["$1" == "-a"]
then 
  cd /home/ian/dustbin
  rm -rf*
  cd /home/ian
  rm store
  touch store
else
  cd /home/ian/dustbin
  ls > dustbin
  for line in `cat dustbin`
  do
    echo "Do you want to delete?" $line
    echo "Y/N"
    read ans
    case "ans" in
      Y) rm $line;;
      N) "";;
    esac
  done
  rm dustbin
  cd
  rm store
  touch store
fi

restore script

#!/bin/bash
if [ "$1" == "-n" ]
then
  cd /home/ian/dustbin
  restore =`grep $2 /home/ian/store`		
  filename = `basename "$restore"`		
  echo "Where do you want to save to?"
  read location
  location1 = `readlink -f $location`		
  mv -i $filename "$location1"/$filename		
else
##if the restore script is run without the -n switch the file will be restored to its original location
  cd /home/ian/dustbin				
  restore = `grep $1 /home/ian/store`		
  filename=`basename "$restore"`			
  mv -i $filename $location			
fi
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    Edinburgh Napier University , Edinburgh , UK , Dr Alistair Armitage , CSN08101 Systems and Services

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

***********************************

I am just looking to see if there is anything I can do to improve the scripts?

Any help would be appreciated

Restore function should test to ensure file they are trying to restore is actually in the dustbin.

Check for upper or lower case responses in your case statements (could also consider looping with a trap for non YorN answers):

     case $ans in
        Y|y) rm "$file";;
        N|n) ;;
        *) echo "Please answer Y or N" ;;

Couple of simplification tips:

To truncate a file you can use:

> store

Instead of piping ls to a tempfile and reading it back, try:

(also consider a renamed of variable to "file" to make things more self-documenting):

for file in *
do
   . . .
done