From owner-freebsd-chat Fri Sep 7 19:14:26 2001 Delivered-To: freebsd-chat@freebsd.org Received: from moo.sysabend.org (moo.sysabend.org [63.86.88.201]) by hub.freebsd.org (Postfix) with ESMTP id 2317137B405 for ; Fri, 7 Sep 2001 19:14:23 -0700 (PDT) Received: by moo.sysabend.org (Postfix, from userid 1004) id 58608756B; Fri, 7 Sep 2001 19:16:16 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by moo.sysabend.org (Postfix) with ESMTP id 559931D89; Fri, 7 Sep 2001 19:16:16 -0700 (PDT) Date: Fri, 7 Sep 2001 19:16:16 -0700 (PDT) From: Jamie Bowden To: Giorgos Keramidas Cc: chat@freebsd.org Subject: Re: cat(1) strangeness when '-' and options are combined In-Reply-To: <20010908010405.A13448@hades.hell.gr> Message-ID: Approved: yep X-representing: Only myself. X-badge: We don't need no stinking badges. X-obligatory-profanity: Fuck X-moo: Moo. MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message