Using the bourne shell /bin/sh write the utility called trash that satisfies the
ID: 3839011 • Letter: U
Question
Using the bourne shell /bin/sh write the utility called trash that satisfies the following specifications:
Usage: trash -l | -p | { filename }*
trash is a replacement for the rm utility. Rather than removing files, trash moves files into a subdirectory called .trash in your home directory. When there is a valid file to move, if .trash doesn't exist, it is created. if .trash exists, the -l option lists the current contents. if .trash exists, the -p option removes the directory and all files in it. Your script should handle any number of files.
Explanation / Answer
SCRIPT:
#!/bin/bash
if [ "$1" = "-p" ] && [ -d $HOME/trash ]; then
rm -r $HOME/trash
elif [ "$1" = "-l" ] && [ -d $HOME/trash ]; then
ls -l $HOME/trash
else
if [ ! -d $HOME/trash ]; then
mkdir $HOME/trash
fi
until [ "$#" = "0" ];do
mv $1 "$HOME/trash"
shift
done
fi
OUTPUT:
sh-4.2$ bash -f final.sh Newfile.txt
sh-4.2$ bash -f final.sh -l
total 4
-rw-r--r-- 1 60581 60581 4 May 13 21:03 Newfile.txt
sh-4.2$ bash -f final.sh -p
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.