Write a program called myrm that takes as arguments the names of files to be removed. If the global variable MAXFILES is set, take it as the maximum number of files to remove without question. If the variable is not set, use 10 as the maximum. If the number of files to be removed exceeds this count, ask the user for confirmation before removing the files.
$ ls | we -l
25
$ myrm * Remove them all
Remove 25 files (y/n)? n
files not removed
$ MAXFILES=l00 myrm *
$ ls
$ All files removed
If MAXFILES is set to zero, the check should be suppressed.
# Set maxfiles to environmental variable MAXFILES, if set, or 10
maxfiles=${MAXFILES:-10}
if [ $maxfiles -eq 0 ] ; then
maxfiles=9999 # skip test if maxfiles = 0
fi
# how many files did the user specify they want removed?
files=$( ls $@ | wc -l )
if [ $files -gt $maxfiles ] ; then
echo "Remove $files files (y/n)? \c" ; read answer
if [ "$answer" != "y" ] ; then
echo "Remove cancelled."
exit 1
fi
fi
rm $@
You might also like to view...
The option for changing text from Paragraph Layout to Column Layout is on the ________ tab
Fill in the blank(s) with correct word
Which of the following is NOT an example of a download?
A. Putting pictures from the Internet on your hard drive. B. Storing a map for your vacation from the Internet on your hard drive. C. Saving a presentation to a CD. D. Saving a program from an Internet site to your hard drive.