[comp.unix.questions] More categories for aliases

creps@silver (Steve Creps) (06/01/88)

   Someone posted an article about uses for aliases, and gave three categories,
asking for any others. I was unable to post to this group at the time (due to
config problems at our site that have since been fixed), and the article seems
to have expired now. Anyway, I have two more categories to add.

- To set default flags for a command (i.e. "alias rm rm -i" makes -i a default
  flag for rm instead of -f)

- To customize a command (i.e. "alias finger finger \| sort" customizes the
  finger command so that output is sorted)

-	-	-	-	-	-	-	-	-	-
Steve Creps, Indiana University, Bloomington, home of the "Hoosiers"
	creps@silver.bacs.indiana.edu (192.12.206.2)
	{pur-ee,ihnp4!inuxc,rutgers,pyramid}!iuvax!silver!creps
	creps@iubacs.bitnet (forwarded)
"To dream... the unlintable dream..."

ok@quintus.UUCP (Richard A. O'Keefe) (06/01/88)

In article <1827@silver.bacs.indiana.edu>, creps@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.

creps@silver.bacs.indiana.edu (Steve Creps) (06/02/88)

In article <1044@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
>In article <1827@silver.bacs.indiana.edu>, creps@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.

-	-	-	-	-	-	-	-	-	-
Steve Creps, Indiana University, Bloomington, home of the "Hoosiers"
	creps@silver.bacs.indiana.edu (192.12.206.2)
	{pur-ee,ihnp4!inuxc,rutgers,pyramid}!iuvax!silver!creps
	creps@iubacs.bitnet (forwarded)
"To dream... the unlintable dream..."

mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) (06/02/88)

>>"-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

On Ultrix 2.2, "-f" is most certainly NOT the default (neither is "-i").  The
difference between -f and the default is that in the default case, "rm" will
ask "OK to override mode xxx" (or something like that) if you don't have write
permission for the file in question, whereas "rm -f" doesn't do that check.

Mike Khaw
-- 
internet: mkhaw@teknowledge.arpa
uucp:	  {uunet|sun|ucbvax|decwrl|uw-beaver}!mkhaw%teknowledge-vaxc.arpa
hardcopy: Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

ok@quintus.UUCP (Richard A. O'Keefe) (06/02/88)

In article <1833@silver.bacs.indiana.edu>, creps@silver.bacs.indiana.edu (Steve Creps) writes:
> In article <1044@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
> >In article <1827@silver.bacs.indiana.edu>, creps@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.)

rml@hpfcdc.HP.COM (Bob Lenk) (06/03/88)

> Oddly enough, "-f" is redundant, the same effect can be obtained by doing
> 	rm </dev/null -options.. files...

Not quite.  -f supresses error messages, such as

	rm: <name> non-existent

Of course you can do

> 	rm -options.. files... < /dev/null 2> /dev/null

		Bob Lenk
		{ihnp4, hplabs}!hpfcla!rml
		rml%hpfcla@hplabs.hp.com

chris@mimsy.UUCP (06/05/88)

[name deleted somewhere writes]
>>Oddly enough, "-f" is redundant, the same effect can be obtained by doing
>>	rm </dev/null -options.. files...

In article <5740022@hpfcdc.HP.COM> rml@hpfcdc.HP.COM (Bob Lenk) answers
>Not quite.  -f supresses error messages, such as
>
>	rm: <name> non-existent

	% rm nosuch
	rm: nosuch nonexistent
	% rm nosuch </dev/null
	%

In 4.2/4.3BSD, at least, there is a line like

	if (!isatty(0)) fflag = 1;

in the source to /bin/rm.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

rml@hpfcdc.HP.COM (Bob Lenk) (06/07/88)

>	% rm nosuch
>	rm: nosuch nonexistent
>	% rm nosuch </dev/null
>	%
>
> In 4.2/4.3BSD, at least, there is a line like
>
>	if (!isatty(0)) fflag = 1;

Just another BSD/SysV difference, which explains the differing opinions
(apparently the hyphen in "non-existent" is another):

	% rm nosuch
	rm: nosuch non-existent
	% rm nosuch < /dev/null
	rm: nosuch non-existent
	% rm -f nosuch
	% 

		Bob Lenk
		{ihnp4, hplabs}!hpfcla!rml
		rml%hpfcla@hplabs.hp.com

morrell@hpsal2.HP.COM (Michael Morrell) (06/10/88)

/ hpsal2:comp.unix.questions / rml@hpfcdc.HP.COM (Bob Lenk) /  5:37 pm  Jun  6, 1988 /
>	% rm nosuch
>	rm: nosuch nonexistent
>
> In 4.2/4.3BSD, at least, there is a line like
>
>	if (!isatty(0)) fflag = 1;

Just another BSD/SysV difference, which explains the differing opinions
(apparently the hyphen in "non-existent" is another):

	% rm nosuch
	rm: nosuch non-existent
----------

Of course, according to my Webster's 9th Collegiate, "nonexistent" is not
hyphenated.  so, in this case, BSD is correct.