End-of-file character (was script > mumble)

Bennet Yee bsy at PLAY.MACH.CS.CMU.EDU
Wed Oct 12 08:21:18 AEST 1988


In article <1503 at fireball.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>In article <503 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>\... here's some source code:
>[C source deleted]
>
>People, what happened to good old shell script programming?
>
>BSD:
>sh -c 'stty all 2> /tmp/stty.$$; set `tail -1 /tmp/stty.$$`;
>	shift; shift; echo $9; /bin/rm /tmp/stty.$$'
>SysV:
>sh -c 'stty -a | sed -e "s/.*eof = \([^;]*\).*/\1/" -e q'
>
>BTW, this shows the SysV stty(1) command is favorable in one way: if stdout
>isn't a tty, try stderr or stdin! (So we won't need the stupid temp file.)


No no no no.  With even BSD stty, you can do it all in one line w/o stupid
tmp files:

  sh -c 'set `stty all 2>&1 >/dev/tty | tail -1`; shift; shift; echo $9'

or, if you don't like the tail, you could also use

  sh -c 'stty all 2>&1 > /dev/tty | awk "{ last = \$NF } END { print last }"'

What _did_ happen to good olde shell programming?

-bsy








-- 
Internet:	bsy at cs.cmu.edu		Bitnet:	bsy%cs.cmu.edu%smtp at interbit
CSnet:	bsy%cs.cmu.edu at relay.cs.net	Uucp:	...!seismo!cs.cmu.edu!bsy
USPS:	Bennet Yee, CS Dept, CMU, Pittsburgh, PA 15213-3890
Voice:	(412) 268-7571



More information about the Comp.unix.wizards mailing list