Write a utility called junk that is a replacement for the rm utility. Rather tha
ID: 3640411 • Letter: W
Question
Write a utility called junk that is a replacement for the rm utility.
Rather than removing files, it moves them into the subdirectory ".junk"
in your home directory. If ".junk" doesn't exist, it is automatically
created.
Create a menu with four options:
1) Move a file to .junk
2) List files in .junk
3) Purge files in .junk
4) Exit
Remember to comment your script liberally.
Also retrieve a file from any directory to current directory.
Submit the script as well as evidence that all options work.
That could include confirmation messages that a file was moved to .junk
as well as a list of files purged from .junk.
Explanation / Answer
PS: Please rate the answer Save this as junk (without any extension). Then right click on the file and give executing permissions. To test do, ./junk somefilename if [ $# != 1 ] then echo "junk: One argument required" >&2 exit 1 fi if [ ! -d $HOME/.junk ] then mkdir $HOME/.junk fi case "$1" in -l) ls -l $HOME/.junk | tail +2 exit 0 ;; -p) rm -r $HOME/.junk exit 0 ;; *) if [ ! -w "$1" ] then echo "junk: No write permission for file $1" >&2 exit 1 fi mv "$1" $HOME/.junk exit 0 ;; esac
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.