More categories for aliases (was Re: something or other)

Richard A. O'Keefe ok at quintus.UUCP
Thu Jun 2 14:55:11 AEST 1988


In article <1833 at silver.bacs.indiana.edu>, creps at silver.bacs.indiana.edu (Steve Creps) writes:
> In article <1044 at cresswell.quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
> >In article <1827 at silver.bacs.indiana.edu>, creps at silver (Steve Creps) writes:
> >> - To set default flags for a command (i.e. "alias rm rm -i" makes -i a default
> >>   flag for rm instead of -f)
> >"-f" is NOT a default for rm.
> 
>    It is on our system (which runs Ultrix 2.0). Actually, from what I've heard
> on the net, "-f" is indeed the default for rm on most Unix-based systems. At
> least, I've heard people say "-f" is the default, but have never before heard
> anyone say "-i" is.

Somebody is confused here, and just for once I'm pretty sure it isn't me.
I *have* checked the Ultrix manuals, also the SVID.  There are THREE
possible modes:

    -i	Ask about *every* file

DEFAULT	Ask before removing a file if
	(standard input is a terminal) and
	(no write permission for file to be deleted)

    -f	Don't ask about *any* files.

"-f" is not the default in either System V or BSD, including Ultrix.
The default mode hasn't got an option letter which can force it (but
see below).

Oddly enough, "-f" is redundant, the same effect can be obtained by doing
	rm </dev/null -options.. files...
If you want the default behaviour in a script (that is, you want to be
prompted when the script tries to remove a file you lack write permission
for) you can exploit the sensitivity to standard input by doing
	rm </dev/tty -options.. files..
This will work even if the script is being used in a pipe-line.

Beware of using "rm -i" in a script: in this mode it does NOT check that
it is reading from the standard input, and it will write its prompt and
read from the current input, whatever that is.  So if you have a script
using rm -i and that script is used in a pipe, it will read from the
wrong place.  If you are going to alias rm at all (which is a remarkably
silly thing to do; why not introduce an alias 'del' instead and avoid
breaking any scripts) it would be better to do
	rm </dev/tty >/dev/tty -i -options.. files..
to ensure that the prompts go to the right place and the response is
read from the right place.

Recommendations:
(1) R the FM carefully!
(2) DO NOT ALIAS BASIC COMMANDS, you'll break scripts.
    (Or if you feel that you *must* alias basic commands, always write
    your scripts in Bournese so that they won't be broken.)
(3) alias del 'rm </dev/tty >/dev/tty -i \!*'
    (If you want something you can use in scripts.)



More information about the Comp.unix.questions mailing list