From: Andrew Church Subject: Re: Commentary on: Bash Command Leads to ... Date: Tue, 03 Feb 2026 16:49:27 +0900
>>Imagine you run a command like "stty" which alters the terminal state >>(intentionally). You wouldn't want bash to undo this. So, if stty >>exits in a normal manner, the terminal changes are retained. ... >As someone who's been bitten by this occasionally, though never badly >enough to look into the issue in detail, I'm wondering -- would it be >reasonable for bash to limit its interpretation of a "normal" exit to >"WIFEXITED(status) && WEXITSTATUS(status) == 0"? Conversely, is there >any case in which one would want to retain changes made to the terminal >state when stty or a similar program exits with a non-zero status? >(My "man stty" says nothing about the exit status, so it's entirely >possible I'm missing some subtleties.) I get that most of the posters/commentators here are trying hard to honor the general Unix idea of "Trust the user; if the user asks for something, give it to them" - in this case, we are trying hard to say that if the user changes the stty params in an interactive shell, we should honor that change. But here, I would argue the converse - and that I really think tcsh has it right. The point is that I can't think of an actual use case where you'd want to change (permanently, if you see what I mean) the stty modes for an interactive shell session. I'd argue that if they change, it is almost certainly a mistake and the shell is right to correct it. Now, this of course doesn't apply to a script; a script can change the params and do what it likes, but they should be restored when the shell regains control. Note, incidentally, that way, way, back in the old days - when Unix was more trusting and it was normal to have your tty world-writable (so that the write(1) command worked), we would sometimes, as a prank, do "stty 0" on another user's (serial) connection, just to screw them up. If their shell didn't fix this, this would effectively knock them off the system. What fun! ================================================================================= Please do not send me replies to my posts on the list. I always read the replies via the web archive, so CC'ing to me is unnecessary. When responding to my posts, please try to refrain from giving bureaucratic answers. If you have nothing useful to say, then just click Next and go on.
