Unix Shell Scripting – Remake the rm command with a trashbin

Below is the code to remake the rm command. I remade it so I could send everything i delete to a trashbin. It sends it to your home/.Trashbin. If the directory isnt there, it makes it for you. After that it tests to see if there are any arguments after the command, and if there are 0 it sends back a message. If there are arguments it continues. If the second argument is the -r flag then it send everything after the flag to the trashbin, no matter what. If there isnt the -r present then it only sends files to the trashbin, and if it finds out you tried to delete a directory, it sends back an error. This was made in a bourne-again shell.

Thanks!

Checkout the code below.

#!/bin/sh
if ! test -d $HOME/.Trashcan
   then
   mkdir $HOME/.Trashcan
fi
if test $# -eq 0
  then
    echo $0:missing operand - moron
exit 1
fi
if test $1 = "-r"
  then
  shift
    for stuff in $*
    do
  if test -d $stuff
  then
    mv $stuff $HOME/.Trashcan
      elif test -f $stuff
    then
        mv $stuff $HOME/.Trashcan
fi
done
  else
    for stuff2 in $*
    do
if test -f $stuff2
  then
  mv $stuff2 $HOME/.Trashcan
fi
  if test -d $stuff2
  then
    echo "myrm: cannot remove $stuff2: Is a directory. moron"
fi
done
fi

One Response

  1. Tracey Romero Says:

    hi
    skevb1uv39hu38z2
    good luck

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.