Date: Sat, 8 Sep 2001 01:04:05 +0300 From: Giorgos Keramidas <charon@labs.gr> To: chat@freebsd.org Subject: cat(1) strangeness when '-' and options are combined Message-ID: <20010908010405.A13448@hades.hell.gr>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010908010405.A13448>