bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stty not restored in trap when executing read with options


From: Chet Ramey
Subject: Re: stty not restored in trap when executing read with options
Date: Mon, 24 Jul 2017 10:35:24 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 7/16/17 6:59 PM, Quentin L'Hours wrote:
> Hello,
> 
> bash: 4.4.12(1)-release
> stty: 8.25 (GNU version)
> 
> When running this small script:
> 
>> trap 'stty echo; exit 0' INT
>> stty -echo
>> read -d a
> 
> and hitting Ctrl-c
> 
> stty should be restored in the trap, but doesn't (the trap code is executed
> though).
> This also seems to happen with read -s and -n options.

This is pretty easy to explain.  The read builtin takes great care to
restore the terminal settings it changes before the shell exits.

This was prompted by several bug reports over time, the last of which
(the one that finally resulted in the change) is:

http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00151.html

If the shell exits as the result of a signal, even if it exits out of a
trap handler, the read builtin restores the terminal attributes that
were in effect when it was invoked.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]