[mod.std.unix] A convention for -file

std-unix@ut-sally.UUCP (10/27/86)

From: weemba@brahms.berkeley.edu (Matthew P Wiener)
Date: Fri, 24 Oct 86 14:27:50 PDT
Organization: University of California, Berkeley

In article <6029@ut-sally.UUCP> Mark Horton writes:
>	Since many commands take names beginning with "-" as flags,
>		file names beginning with "-" don't always work.

There's a real easy fix to the current random collection of special
flags that handle filenames beginning with a dash: always interpret
two dashes at the beginning of a command line argument as the name for
the file obtained by eliding the two dashes into one.  Thus

% rm --xyz ----xyz

would mean remove -xyz ---xyz, etc.  It's completely unambiguous,
until some clown comes up with flags needing two dashes.  Similarly
for ++file with commands using + flags.

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720

Volume-Number: Volume 7, Number 91

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (10/28/86)

From: guy@sun.com (Guy Harris)
Date: Mon, 27 Oct 86 12:44:39 PST

> There's a real easy fix to the current random collection of special
> flags that handle filenames beginning with a dash:...

There's another fix, already implemented by all the versions of "getopt"
running around - an argument of the form "--" means no other arguments are
to be interpreted as flags, regardless of their form.  Since this one has
already been implemented by many commands, it is preferable.

Volume-Number: Volume 7, Number 95

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (10/28/86)

From: weemba@brahms.berkeley.edu (Matthew P Wiener)
Date: Mon, 27 Oct 86 23:12:03 PST
Organization: University of California, Berkeley

In article <6121@ut-sally.UUCP> Guy Harris writes:
>There's another fix, already implemented by all the versions of "getopt"
>running around - an argument of the form "--" means no other arguments are
>to be interpreted as flags, regardless of their form.

But such breaks on commands that take flags after the argument name, like
cc, lxref, od.

>						        Since this one has
>already been implemented by many commands, it is preferable.

Huh??  Why bother debating standards then?  I once got the argument that
integer division should round towards 0, not towards minus infinity, since
that's how Fortran did it.  I was new to the net then, and I was stunned.

I do not count appeal to the past or even the present as the definition of
preferable, although I agree that it can be a major factor.  But I dislike
it when it is paraded as THE reason for saying its preferable.  Is UNIX
supposed to turn into an official fossil now?

I say my suggestion is cleaner and more versatile, thus it is preferable.
The required reprogramming would not be that complicated--just a minor
nuisance.

But if you wish appeals to history, my suggestion is after all the same
as the ancient doubled quote => single quote within quoted strings con-
vention from days of yore.  In retrospect, it's perhaps a bit surprising
that something like this wasn't adopted from the beginning.

Not that I care.  *I* don't put dashes at the beginning of my file names.
(Joke, everyone, just a joke.)

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720

Volume-Number: Volume 7, Number 97

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (10/29/86)

From: byee@f.gp.cs.cmu.edu (Bennet Yee)
Date: Tue, 28 Oct 1986 14:17-EDT

There is nothing wrong with the old standby of "./-file" -- why all the
fuss with special-casing in getopt or "--file"?

-Bsy

--
Bennet Yee							~   ~
								O   =
byee@f.gp.cs.cmu.edu		(Arpa)				  ^
...!seismo!f.gp.cs.cmu.edu!byee	(Uucp)				\___/

Volume-Number: Volume 8, Number 7

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (10/31/86)

From: guy@sun.com (Guy Harris)
Date: Tue, 28 Oct 86 23:20:53 PST

> >						        Since this one has
> >already been implemented by many commands, it is preferable.

> ...But I dislike it when it is paraded as THE reason for saying its
> preferable.  Is UNIX supposed to turn into an official fossil now?

I saw no great advantage offered by the proposed scheme.  It was more
"different" than it was "better".  I'll complete the thought, then: "Since
this one has already been implemented by many commands, since it requires less
reprogramming than changing all commands that accept flag arguments to
special-case arguments beginning with "--", and since it would be a novelty
to more users than the "'--' quotes a '-'" convention would be, it is
preferable."

> I say my suggestion is cleaner and more versatile, thus it is preferable.

I don't see how it is any "cleaner" than "--", although this depends on what
"cleaner" means.  It is slightly more versatile, in that it is not
context-dependent; however, this is not sufficient to make it preferable.
The cost of changing existing programs to use the "'--' quotes a '-'"
convention that is greater than the cost to changing them to use the
"getopt" convention.

> The required reprogramming would not be that complicated--just a minor
> nuisance.

No, it is not necessarily *complicated*, but that doesn't render it merely a
"minor nuisance".  It requires that all *non*-flag arguments be treated
specially.  Programs that accept flag arguments already treat them
specially.  Those that use "getopt" need not change at all.  Those that do
not can either be converted to use "getopt", or just be converted to
recognize a flag of the form "--" as an indication that no subsequent
arguments be treated as flag arguments.

> But if you wish appeals to history, ...

I *don't* want appeals to history; my comment was an appeal to existing
practice, and more specifically existing practice in the area of command
argument parsing.

Volume-Number: Volume 8, Number 8

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (11/02/86)

From: seismo!unido!exunido!hmm (Hans-Martin Mosner)
Date: Sat, 1 Nov 86 03:10:54 +0100

One problem with all the methods for escaping -file is that wildcard expansion
by the shell will still get the real names.  So if I happen to have a file
"-rf" in my home directory and do a "rm *f", I'm out of luck :-)
I have no solution for this, though...

	Hans-Martin Mosner
	University of Dortmund (W. Germany)

Volume-Number: Volume 8, Number 17

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (11/03/86)

[ I'm not positive anything in this article has not been said before,
but it's a useful summary.  -mod ]

From: nike!pyramid!pyrtech!trwrb!desint!geoff (Geoff Kuenning)
Date: Wed, 29 Oct 86 01:02:04 pst
Organization: SAH Consulting, Manhattan Beach, CA

In article <6110@ut-sally.UUCP> weemba@brahms.berkeley.edu (Matthew P Wiener)
writes:

> Date: Fri, 24 Oct 86 14:27:50 PDT
> Organization: University of California, Berkeley
> 
> In article <6029@ut-sally.UUCP> Mark Horton writes:
> >	Since many commands take names beginning with "-" as flags,
> >		file names beginning with "-" don't always work.
> 
> There's a real easy fix to the current random collection of special
> flags that handle filenames beginning with a dash: always interpret
> two dashes at the beginning of a command line argument as the name for
> the file obtained by eliding the two dashes into one.  Thus

There're at least two reasons not to do this:  (1) it's unnecessary, and
(2) it conflicts with the standard already established for getopt(3).

It's unnecessary because you can *always* specify a file beginning with
"-" as "./-file".  I find this much easier to remember.

The second reason is that getopt(3) already explicitly defines an argument
of "--" as delimiting the end of the switches.  It is provided specifically
to handle the case when an argument begins with a dash.

Thus, for example, to grep(1) for commands that take a "-i" switch, we
would use:

	egrep -- -i /usr/man/u_man/man1/*

(Note that this applies only on System V;  BSD uses an older convention.
Also note that some System V documentation incorrectly lists the obsolete
"-e" switch for this purpose;  "-e" doesn't work, but "--" does.)
-- 

	Geoff Kuenning
	{hplabs,ihnp4}!trwrb!desint!geoff

Volume-Number: Volume 8, Number 27

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (11/05/86)

From: seismo!hadron!jsdy@sally.utexas.edu (Joseph S. D. Yao)
Date: Tue, 4 Nov 86 23:13:22 est
Organization: Hadron, Inc., Fairfax, VA

In article <6197@ut-sally.UUCP>:
>From: seismo!unido!exunido!hmm (Hans-Martin Mosner)
>Date: Sat, 1 Nov 86 03:10:54 +0100
>					 ...  So if I happen to have a file
>"-rf" in my home directory and do a "rm *f", I'm out of luck :-)
>I have no solution for this, though...

At least two others have mentioned that something like ./*f does
wonders (if you are aware that it's needed).  My question is, does
anyone have a need for files that start with '-'?  Or is an ounce
of prevention (not using such files) still worth a pound of cure?
(Ignore troff font files: I try to.)

Side note:  the Instructional WorkBench (IWB), in its Unix(R)
Fundamentals course, makes specific note that one should avoid
making files starting with '+' or '-'.  It makes this the specific
subject of one of its programmed-learning questions.
-- 

	Joe Yao		hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}
			jsdy@hadron.COM (not yet domainised)

Volume-Number: Volume 8, Number 40

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (11/05/86)

From: seismo!mcvax!guido (Guido van Rossum)
Date: Wed, 05 Nov 86 11:24:11 +0100

What nobody seems to have noticed about the proposed "solution" to file
names starting with "-" by prefixing another "-", is that it would break
shell file name expansion.  If you have a file "-foo" in your directory,
the call
	$ blurfl *
will see an option "-foo" rather than a file "--foo".  You can't build
a remedy into the shell's file name generation mechanism unless you plan
to fix all software that ever processes an argv list at the same time
(or build knowledge about programs' command conventions into the shell).

By the way, prefixing with "./" doesn't work at all times either: the
argument need not be a file.  Ever tried to grep for "-1"?  (Grep has a
solution built in: grep -e).

	Guido van Rossum, CWI, Amsterdam <guido@mcvax.uucp>

Volume-Number: Volume 8, Number 42

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (11/07/86)

From: weemba@brahms.berkeley.edu (Matthew P Wiener)
Date: Fri, 7 Nov 86 03:02:53 PST
Organization: University of California, Berkeley

In article <6239@ut-sally.UUCP> seismo!mcvax!guido (Guido van Rossum) writes:
>What nobody seems to have noticed about the proposed "solution" to file
>names starting with "-" by prefixing another "-", is that it would break
>shell file name expansion.

Of course, but it is trivial (if ugly) to get around, using backquotes.

The reason I am interested is because it came up years ago.  I overloaded
the command line with arguments so that my program could run on our high
speed batch only machine.  And there was one die hard from our batch machine
who liked punctuation marks as his first character.  (The other machine had
a completely different argument convention, so there were different taboo
names.)  And yes, I had strings and post-filename flags in the command line
to boot.

If getopt is to be the standard, a -+ flag to turn flags back on should be
added.  Except for -- -+, meaning file -+.  (But then, somebody is going to
break on that by having a null name show up in between a -- and -+ from an
uncareful $variable expansion.  Weee!)

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720

Volume-Number: Volume 8, Number 48

std-unix@ut-sally.UUCP (Guest Moderator, John B. Chambers) (11/22/86)

References:


>From munnari!runx.oz!dave@seismo.UUCP Thu Nov 20 01:38:54 1986
Date: Wed, 19 Nov 86 22:15:59 AEST
From: munnari!runx.oz!dave@seismo.UUCP (Dave Horsfall)

It is writ:
    Side note:  the Instructional WorkBench (IWB), in its Unix(R)
    Fundamentals course, makes specific note that one should avoid
    making files starting with '+' or '-'.  It makes this the specific
    subject of one of its programmed-learning questions.
    
EVERY Unix manual I've seen has said something like "It is unwise
to use file names starting with '-'".  And I've used Unix since
good ol' Edition 5 ...  Don't people read manuals anymore?


Dave Horsfall
Sun Computer Australia



Volume-Number: Volume 8, Number 59