[net.bugs] Csh and stty

simpson@trwrb.UUCP (08/07/84)

	Here is an interesting anamoly of the C shell and the way it
forks off processes.  When you type "stty everything", you get what
you expect: the state of your terminal using the new tty driver.
When you type "stty everything | more", you get the (confused) old
terminal driver.
-- 
		Scott Simpson
		TRW Electronics and Defense Sector
		...{decvax,randvax,ucbvax,ucivax}!trwrb!{simpson,ssimpson}

burgess@dalcs.UUCP (Chris Burgess) (08/09/84)

The reason why stty appears confused is because stty does ioctl's
on file descriptor 1 which is standard output for your terminal.
If you try to pipe the output through more it does the ioctl's on
file descriptor 1 again, but csh redefines it to the pipe going
into more. The result being that stty is trying to find out the
terminal characteristics of the pipe rather than the terminal.
This feature is useful when you want to get or set the attributes
of another device e.g. "stty everything > /dev/ttyd0" will give
you the characteristics of ttyd0 rather than sending yours as
output to ttyd0.

fair@dual.UUCP (Erik E. Fair) (08/09/84)

Actually, you're getting the stty information for the pipe...
Stty in V7 & 4BSD did the gtty() call on fd #1 (stdout), which
is where your pipe is going. One construction which will do the
right thing is:

	(stty everything > /dev/tty) |& more

The `&' is necessary because V7/4BSD stty prints its output on stderr.

	Erik E. Fair	ucbvax!fair	fair@ucb-arpa.ARPA

	dual!fair@BERKELEY.ARPA
	{ihnp4,ucbvax,hplabs,decwrl,cbosgd,sun,nsc,apple,pyramid}!dual!fair
	Dual Systems Corporation, Berkeley, California

kurt@wucs.UUCP (Kurt Haserodt) (08/09/84)

Your problem with 'stty everything | more' giving you confusing results
(i.e. the old driver) probably stems from the fact that stty uses the
standard output to get its information and do its work, and then prints
its results on the standard error.  Since stdout is now directed to
a pipe, it's unclear what results you should expect.

Personally, I think stty should do its work on the standard input, so that
anything it prints can be EASILY redirected (through a pipe or otherwise),
though I must say that:  stty 1200 >/dev/ttyd0  looks more meaningful than
stty 1200 </dev/ttyd0.
-- 

Kurt Haserodt				..!ihnp4!wucs!kurt
Box 1045 Washington University		(314)-889-6160
St. Louis, MO 63130   USA

dave@utcsrgv.UUCP (Dave Sherman) (08/10/84)

In article <895@trwrb.UUCP> simpson@trwrb.UUCP (Scott Simpson) writes:
~| 
~| 	Here is an interesting anamoly of the C shell and the way it
~| forks off processes.  When you type "stty everything", you get what
~| you expect: the state of your terminal using the new tty driver.
~| When you type "stty everything | more", you get the (confused) old
~| terminal driver.

Sorry, that has nothing whatsoever to do with the way csh forks off
processes. You'll get the same reponse with sh. "stty" sends its
information to stderr, and by default looks on stdout to determine
what the settings are. When you type "stty | more", stty looks down
a pipe, finds no terminal there (and does its best) and puts the
information on the diagnostic output.

Incidentally, it's because stty looks on stdout and writes on stderr
that the way to find out the speed or other parameters of a user on
"ttyx" is the rather curious
	stty > /dev/ttyx


Dave Sherman
Toronto
-- 
 {allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsrgv!dave

guy@rlgvax.UUCP (Guy Harris) (08/10/84)

The USG UNIX solution is, I think, better; the USG "stty" command acts on
its standard *input*.  That way, you can redirect its output; there is an
option to "stty" to dump the terminal modes in a binary (BCHex) form, and to
set them from that form, so shell scripts can save and restore the modes.
Of course, if you don't know about this change, you can get very confused.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy

barmar@mit-eddie.UUCP (Barry Margolin) (08/13/84)

I use Uniplus+ System III, and here "stty" looks at stdin, NOT stdout.
It prints its output on stdout.  This seems like a much more reasonable
arrangement.  There is an option (-g) which makes it output an octal
string that can be used as input for another stty.  Since it outputs on
stdout, this can be used as
	OLDMODES=`stty -g`
	stty ...
	....
	stty $OLDMODES
-- 
    Barry Margolin
    ARPA: barmar@MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar

mcferrin@inuxc.UUCP (P McFerrin) (08/13/84)

Stty on USG 5.0 systems currently uses stdin to get/set terminal characteristics.

However, more (at least on our system) changes the terminal mode so the
stty is printing everything AFTER more has changed things to suit him.