Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Sep 2001 19:16:16 -0700 (PDT)
From:      Jamie Bowden <ragnar@sysabend.org>
To:        Giorgos Keramidas <charon@labs.gr>
Cc:        chat@freebsd.org
Subject:   Re: cat(1) strangeness when '-' and options are combined
Message-ID:  <Pine.BSF.4.10.10109071914420.41287-100000@moo.sysabend.org>
In-Reply-To: <20010908010405.A13448@hades.hell.gr>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 8 Sep 2001, Giorgos Keramidas wrote:

:The manpage of cat(1) says that an argument of '-' is interpreted as
:the filename of 'stdin'.  The cat(1) source uses getopt() to parse its
:args, and '-' has a special meaning for getopt too.  This makes cat(1)
:act in a seemingly strange manner in the following cases:
:
:-:- Running cat(1) without *any* command line switches
:
:If one runs cat as shown below:
:
:	% cat - /etc/fstab -
:
:Then both '-' occurences are considered to be filenames, and you have
:to press once ^D before fstab is displayed, and once more after it's
:printed to stdout, to exit cat.
:
:-:- Running cat(1) with similar command line including some switches
:
:	% cat -b - /etc/fstab -
:
:In this case, the first '-' is eaten up by getopt() after the parsing
:of -b option.  The first '-' is taken by getopt() to mean 'the end of
:command line options'.  Thus, cat numbers all non-blank lines (the -b
:option), but works as if it was called with:
:
:	% cat /etc/fstab -
:
:This is not a bug, since it is the documented way that getopt() works.
:However, it seems to be somewhat confusing :-(
:
:What do the standards-people have to say about this?

It works exactly as I'd expect it to, see below:

7:14pm moo  /home/ragnar %cat -- /etc/fstab
# Device                Mountpoint      FStype  Options         Dump
Pass#
/dev/wd0s1b             none            swap    sw              0       0
/dev/wd0s1a             /               ufs     rw              1       1
/dev/wd0s1f             /usr            ufs     rw              2       2
/dev/wd0s1e             /var            ufs     rw              2       2
proc                    /proc           procfs  rw              0       0

Like many utilies, you need the -- because a single - is a valid filename
in unix.

Jamie Bowden

-- 
"It was half way to Rivendell when the drugs began to take hold"
Hunter S Tolkien "Fear and Loathing in Barad Dur"
Iain Bowen <alaric@alaric.org.uk>



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10109071914420.41287-100000>