fixing rm * (was: Worm/Passwords)
Jeff Venters
venters at argos.uucp
Mon Nov 21 16:15:43 AEST 1988
A simple solution for csh users:
The following alias will prevent wildcard expansions. The actual wildcard
characters will be passed to the script. Add the following alias to your
~/.cshrc:
alias rm ~/bin/del \!\*:q
Next, add the following shell script to your personal "bin" directory (or
wherever you like). Obviously, the script could be made intellegent enough
to recognize "-f" but it would be slower (csh is very inefficient). You
could write a C-program to do this slightly faster (you would still have
to fork a shell to glob the input arguments).
---- CUT HERE -------- CUT HERE -------- CUT HERE -------- CUT HERE ----
#! /bin/csh -f
set nonomatch file=$0 # no wildcard matches allowed/get argv[0]
set exp_names=($argv) # expand wildcards (if any)
#
# if the number words after globbing is not equal to the orignal,
# ask for conformation.
if ($#argv == $#exp_names) then
/bin/rm $exp_names:q
exit $status # exit script here (faster)
else
echo "$file:t: The following $#exp_names files will be deleted:"
# show them the damage they could do
/bin/ls -Fd $exp_names:q
echo -n "Are you sure you want to do this (Y or N)? "
if ($< =~ [Yy]) then
exec /bin/rm $exp_names:q
else
echo ""
echo "$file:t: aborted - no files deleted"
exit (1)
endif
endif
---- CUT HERE -------- CUT HERE -------- CUT HERE -------- CUT HERE ----
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Jeff Venters, Convex Computer Corporation, Richardson, Texas
Internet: venters at convex.COM | UUCP: {uiucuxc,sun,rice}!convex!venters
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
More information about the Comp.unix.wizards
mailing list