waynet@tolerant.UUCP (08/25/87)
A request went out recently for on comp.sources.wanted asking for an rm
that gave a second chance. Remember APRIL 1 ;-)
This one came from someone didn't leave their name on the source.
--
my review intercedes
--
rmsecure - is a script (slow) which will do filename expansion and, if any
wildcards are used, echo the expanded fileset and ask you if
your sure. This gives you a chance to preview your rm fileset.
--
#! /bin/sh
# To extract, remove mail header lines and type "sh filename"
echo x - rmsecure.csh
sed -e 's/^X//' > rmsecure.csh << '!FaR!OuT!'
X#! /bin/csh -f
X# csh script ; secure remove of files
Xonintr out
Xset interact
Xset force
Xset recur
Xset minus
Xwhile ("$1" == "-" || "$1" =~ -[f,i,r])
X switch ($1)
X case -i:
X set interact=-i
X shift
X breaksw
X case -f:
X set force=-f
X shift
X breaksw
X case -r:
X set recur=-r
X shift
X breaksw
X case -:
X set minus=-
X shift
X break
X endsw
Xend
Xif ($interact == -i) then
X /bin/rm -i $force $recur $minus $*
X exit($status)
Xendif
Xset f1=`echo $0`
Xset f1=$f1:t" : remove"
Xset r
Xwhile ("$1" != '')
X set b=`echo $1`
X if ("$b" != '') then
X set noglob
X set a=$1
X unset noglob
X if ("$a" == "$b") then
X set r="$r $b"
X else
X if ($#b == 1) then
X echo -n $f1 $b '? '
X if ( $< == "y" ) then
X set r="$r $b"
X endif
X else
X echo -n $f1 $b '? '| fold
X if ( $< == "y" ) then
X set r="$r $b"
X else
X foreach n ($b)
X echo -n $f1 $n '? '
X if ( $< == "y" ) then
X set r="$r $n"
X endif
X end
X endif
X endif
X endif
X endif
X shift
Xend
X/bin/rm $force $recur $minus $r
Xout:
Xexit(0)
!FaR!OuT!
echo x - rmsecure.doc
sed -e 's/^X//' > rmsecure.doc << '!FaR!OuT!'
XAdding security when removing files:
X------------------------------------
X
XDESCRIPTION:
X------------
XWith the standard "rm", no confirmation is asked when using wild cards;
Xyou surely once experienced that this may be really catastrophic.
XIf not, think about a misstyping like "rm * BAK" instead of "rm *BAK" !!!
X
XA new command, "rmsecure", may prevent this by asking for a confirmation
Xbefore removing any file whose name issued from a wild card expansion.
X
XThis command works a bit slower than the usual "rm", but is really safer !
X
X
XUSE:
X---
XTo use it, you MUST create a special alias like this one:
X
X alias rm '(set noglob; rmsecure \!*)'
X
Xin order to prevent former wild cards expansion by the shell.
X
XWhen used, any list of files resulting from a wild card expansion will be
Xasked globally for confirmation prior to deletion; if answer is negative,
Xeach file in the expanded list will be prompted separatly, like the "-i"
Xoption of usual "rm".
X
XAs reel deletion take place only just before completion of the command,
Xthis one can be safely interrupted at any time if necessary; in this case,
Xno file will be removed.
X
X
XWARNING:
X--------
XFiles whose name is completely specified won't be asked for confirmation,
Xeven if they appear between other arguments using wild cards.
X
X
XLIMITS:
X-------
X - as all expanded file names are concatened within one unique string,
X command can fail due to limitation of shell variable length.
X To overcome this, just select narrowed range.
X
X - due to successive evaluations, any quotes or double quotes will be lost;
X removing files with "strange" names should be done with the standard "rm"
X command using the "-i" option with a "*" wild card.
X
X - the following version is running perfectly with Cshell of 4.2 bsd;
X problems were encountered trying to run it on Unisoft System III,
X probably due to some limitation of the Cshell implemented.
X
!FaR!OuT!
echo x - shar
sed -e 's/^X//' > shar << '!FaR!OuT!'
X#! /bin/sh
X# To extract, remove mail header lines and type "sh filename"
!FaR!OuT!
exit