From owner-freebsd-chat Fri Sep 7 15:30:27 2001 Delivered-To: freebsd-chat@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 0302837B403 for ; Fri, 7 Sep 2001 15:30:24 -0700 (PDT) Received: from hades.hell.gr (patr530-b096.otenet.gr [195.167.121.224]) by mailsrv.otenet.gr (8.11.5/8.11.5) with ESMTP id f87MUKA16319 for ; Sat, 8 Sep 2001 01:30:20 +0300 (EEST) Received: (from charon@localhost) by hades.hell.gr (8.11.6/8.11.6) id f87M46G13581 for chat@freebsd.org; Sat, 8 Sep 2001 01:04:06 +0300 (EEST) (envelope-from charon@labs.gr) Date: Sat, 8 Sep 2001 01:04:05 +0300 From: Giorgos Keramidas To: chat@freebsd.org Subject: cat(1) strangeness when '-' and options are combined Message-ID: <20010908010405.A13448@hades.hell.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-PGP-Fingerprint: 3A 75 52 EB F1 58 56 0D - C5 B8 21 B6 1B 5E 4A C2 X-URL: http://students.ceid.upatras.gr/~keramida/index.html 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 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? -giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message