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

Richard A. O'Keefe ok at quintus.uucp
Wed Oct 12 12:18:34 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?

Well, it's very simple.  I wanted my __C__ programs to be able to remind
their users what to type to get an end-of-file.  So I wrote a C function.
The main() in that file was enclosed in #ifdef TEST, remember!
(I have received some mail pointing out problems, esp. with System V.)

>BSD:
>sh -c 'stty all 2> /tmp/stty.$$; set `tail -1 /tmp/stty.$$`;
>	shift; shift; echo $9; /bin/rm /tmp/stty.$$'

It is very easy to break this (took me 2 minutes),
and in any case on the system I am using I get the answer "^Z/^[",
which is wrong (it should be "^Z").

>SysV:
>sh -c 'stty -a | sed -e "s/.*eof = \([^;]*\).*/\1/" -e q'

It is also easy to break this (took me 5 minutes; I don't know SysV well).

Forking off three programs (sh, stty, rm or sed) would be a very odd thing
to do in a C program when you can get the same information with a few
system calls.

While we're on the subject, I have read the SVID termio(ba_env) section
several times, and cannot tell whether there is any general way of
disabling individual elements of c_cc[] or not.  Setting c_cc[VEOL] to
ASCII NUL appears to disable that feature.  In DYNIX V3.0.12 NFS,
SunOS 3.2, and UNIX System V/386 Release 3.0, setting c_cc[VKILL] to
ASCII NUL merely makes ^@ the kill character.  Does anyone know which
elements of c_cc[] can be suppressed and which can't?



More information about the Comp.unix.wizards mailing list