[Top][All Lists]

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

Re: bash bug with read -s command

From: Chet Ramey
Subject: Re: bash bug with read -s command
Date: Mon, 22 Dec 2014 11:27:28 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 12/21/14 3:28 PM, Richard W. Marsden wrote:
> steps to produce
> hide cursor
>     setterm -cursor off
> call the bash built-in read command as follows: silent, wait 1 second, read
> 1 character to variable KEY
>     read -s -t 1 -n 1 KEY
> while the read command is in a loop, control + c is trapped successfully
> and the cursor is un-hidden
>     setterm -cursor on
> expected results:
>     cursor is visible and typed keys are echoed to screen as before
> actual results:
>     cursor is visible, keys are no-longer echoed to the screen until
> terminal is closed
> additional notes
>     command: setterm -default cannot fix
>     os: fedora 21
>     bash version: bash-4.3.30-2.fc21.x86_64
>     tested in various terminal emulators, and the console (alt+Fn, where 
> n=1-8)
> workaround
>     remove silent -s from read command

There are a couple of things to note here.  First, it's the trap that
causes the problem: it short-circuits the normal exit path that would cause
the terminal to be cleaned up, then just calls exit instead of killing
the shell with SIGINT.  (To see why you should do that, read
http://www.cons.org/cracauer/sigint.html).  If the script died due to
SIGINT, the parent bash would notice and restore the terminal settings.

Second, you can clean this up without any changes to bash by running a
terminal cleanup command (`stty sane', `reset', whatever) in the SIGINT

If you would like to take a look at patching bash so you don't have to
modify your script, take a look at the attached patch.

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

Attachment: restore-term.patch
Description: Source code patch

reply via email to

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