Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

bash: Readline + timeout

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

bash: Readline + timeout

#1 Post by linuxCowboy »

Lately I discovered a regression of one of my aliases:

Code: Select all

reads -t5
which is

Code: Select all

alias reads='read -sep enter'
It closes the tab or window!


Please test with bash in a terminal:

Code: Select all

read -et0
ret:1 okay

Code: Select all

read -et1
ret:142 + exit!

rbash or --norc --noprofile doesn't fix it.

Is it me or just another enhancement went south?

bash/testing,now 5.2~rc2-2 amd64 [installed]
libreadline8/testing,now 8.2~rc2-2 amd64 [installed]

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: bash: Readline + timeout

#2 Post by fabien »

linuxCowboy wrote: 2022-09-22 09:24 Lately I discovered a regression of one of my aliases:

Code: Select all

reads -t5
which is

Code: Select all

alias reads='read -sep enter'
It closes the tab or window!
One thing is unclear in what you describes. It seems you have identified an issue with timing (-t option), but your alias has no such timing option. Can you please clarify this?
linuxCowboy wrote: 2022-09-22 09:24Please test with bash in a terminal:

Code: Select all

read -et0
ret:1 okay

Code: Select all

read -et1
ret:142 + exit!
I think that exit code 142 is normal behaviour.
Based on What are Bash Exit Codes in Linux, 142 is 128+14 (128 + signal 14).
'man 7 signal' identify code 14 to SIGALRM and points to 'man 2 alarm':
alarm - set an alarm clock for delivery of a signal
[...]
alarm() arranges for a SIGALRM signal to be delivered to the calling process in seconds seconds.
If seconds is zero, any pending alarm is canceled.
[...]
sleep(3) may be implemented using SIGALRM
That is to say, if seconds is zero, pending alarm is canceled and Bash returns default error code 1 (because nothing is read), and it returns 128+SIGALRM code if seconds is more than zero and nothing is read.

I have tested (xterm, lxterminal, xfce4-terminal, even if this has certainly nothing to do with terminals): the error codes are the same as yours (which in my understanding is normal), but my terminals, as expected, don't exit. Regarding this unexpected exit, could you please post the output of:

Code: Select all

echo "$SHELLOPTS"
What is weird is that, if I understand well what you say, your terminal doesn't exit with signal 1 but exits when signal 142 occurs. Can you confirm this?

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#3 Post by linuxCowboy »

fabien wrote: 2022-09-22 15:30
linuxCowboy wrote: 2022-09-22 09:24 Lately I discovered a regression of one of my aliases:

Code: Select all

reads -t5
which is

Code: Select all

alias reads='read -sep enter'
It closes the tab or window!
One thing is unclear in what you describes. It seems you have identified an issue with timing (-t option), but your alias has no such timing option. Can you please clarify this?
This is on purpose. So I get a wait in a lengthy script, but sometimes add a timeout with -t.
I have tested (xterm, lxterminal, xfce4-terminal, even if this has certainly nothing to do with terminals)
Thanks. Return value 1 and 142 are okay. SHELLOPTS and BASHOPTS are okay.

My Preliminary status is - its bash.

bash 5.2.0(1)-alpha is the culprit. I thought at first libreadline8, but bash his own version off it.

You can load bash-5.2-alpha.tar.gz, or use it in git tag: bash-5.2-alpha

But thats a huge commit! The CHANGES file has 10,000+ lines.

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: bash: Readline + timeout

#4 Post by fabien »

I overlooked your Bash version. I tested with testing, still no problem.

Code: Select all

$> read -t0 || echo "$?" ; read -t1 || echo "$?" ; echo -e "\n$BASHOPTS\n\n$SHELLOPTS\n\n$BASH_VERSION" ; cat /etc/debian_version ; uname -a
1
142

checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:globasciiranges:globskipdots:interactive_comments:login_shell:patsub_replacement:progcomp:promptvars:sourcepath

braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor

5.2.0(1)-rc2
bookworm/sid
Linux virtdeb9 5.19.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.19.6-1 (2022-09-01) x86_64 GNU/Linux
What we can say for sure is that testing is for testing and alpha is... alpha.

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#5 Post by linuxCowboy »

You're right, it's testing.

And a case for git bisect!

The culprit is:

Code: Select all

commit 2fe2e8197eb8f05c22a23b9d1e115d74febc8325
Author: Chet Ramey <chet.ramey@case.edu>
Date:   Thu Mar 11 18:41:17 2021 -0500

    application-settable readline timeouts
The error-test is

Code: Select all

$ echo $SHLVL
1

$ ./bash
$ read -et1
$ echo $SHLVL
1  # error: 1  okay: 2

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: bash: Readline + timeout

#6 Post by fabien »

See https://mail.gnu.org/archive/html/bug-b ... 00129.html
This document details the changes between this version, bash-5.2-beta, and
the previous version, bash-5.2-alpha.
[...]
1. Changes to Bash
[...]
e. Fixed an issue with read timeouts in posix mode.

This document details the changes between this version, bash-5.2-alpha, and
the previous version, bash-5.1-release.
[...]
3. New Features in Bash
[...]
b. There is a new internal timer framework used for read builtin timeouts.
[...]
4. New Features in Readline
[...]
c. There is a new framework for readline timeouts, including new public
functions to set timeouts and query how much time is remaining before a
timeout hits, and a hook function that can trigger when readline times
out. There is a new state value to indicate a timeout.
So do you confirm that Bash 5.2.0(1)-rc2 solved your issue?

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: bash: Readline + timeout

#7 Post by fabien »

Well no, Bash 5.2.2(1)-release didn't solve the issue. I opened a Debian bug and a Bash bug. Upstream has acknowledged a regression.
linuxCowboy wrote: 2022-09-25 11:23 The culprit is:

Code: Select all

commit 2fe2e8197eb8f05c22a23b9d1e115d74febc8325
Author: Chet Ramey <chet.ramey@case.edu>
Date:   Thu Mar 11 18:41:17 2021 -0500

    application-settable readline timeouts
You were perfectly right! I have to apologize for not having tested with the -e option, to be put down to fatigue I guess.
Hopefully we'll soon have a working version.

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#8 Post by linuxCowboy »

Yes its fixed, thank you!

Unfortunately, this cool alias

Code: Select all

alias reads='read -sep enter'
still doesn't perform as before the enhancement.

... But you can use

Code: Select all

alias reads="read -sp enter$'\r'"
to enjoy it again. This works also with previous bash versions.

... at least until the next enhancement :wink:

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#9 Post by linuxCowboy »

You can also use a boringly normal function:

Code: Select all

readf () { read -sp enter $*; echo -en '\r     \r';}
cmdline or script:

Code: Select all

readf

readf -t3

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#10 Post by linuxCowboy »

And a little less boring:

Code: Select all

unalias reads

reads () { read -sp enter ${1+-t$1}; echo -en "\r     \r";}
with

Code: Select all

reads 3
This seems to be a real enhancement. Although my cool alias is gone... R.I.P.

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#11 Post by linuxCowboy »

It starts to getting cool again:

Code: Select all

reads () { read ${1+-t$1} -sp "${2-Enter}"; printf "\r%${COLUMNS-80}s\r";}

Code: Select all

reads 3 "Is it love?"

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#12 Post by linuxCowboy »

The timeout should be optional and echo'd:

Code: Select all

reads () 
{
        local t
        [[ $1 =~ ^[0-9]+$ ]] && t=$1 && shift

        read ${t:+-t$t} -sp "(${t:-~}) ${1-Enter}" ${@:2}

        printf "\r%${COLUMNS-80}s\r"
}

Code: Select all

$ reads "what to do with the germans?" answer
(~) what to do with the germans?
$ echo $answer
cut off their gas and atom. yours truly, deep state
functional, but bloat!

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#13 Post by linuxCowboy »

golf

for some reason local t is like unset, so we can spare two bytes:

Code: Select all

reads () 
{
        local t
        [[ $1 =~ ^[0-9]+$ ]] && t=$1 && shift

        read ${t+-t$t} -sp "(${t-~}) ${1-Enter}" ${@:2}

        printf "\r%${COLUMNS-80}s\r"
}
Its half documented, but logical.

local t= is empty.

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#14 Post by linuxCowboy »

golf

Code: Select all

reads () 
{
        local t
        [[ $1 =~ ^[0-9]+$ ]] && t=$1 && shift

        read ${t+-t$t} -sp "(${t-~}) ${1-Enter}"

        printf "\r\e[K"
}
grabbed from grep.

linuxCowboy
Posts: 15
Joined: 2022-09-22 09:02
Been thanked: 1 time

Re: bash: Readline + timeout

#15 Post by linuxCowboy »

Sometimes you want the output:

Code: Select all

reads(){ local t;[[ $1 =~ ^[0-9]+$ ]]&&t=$1&&shift;read ${t+-t$t} -sp"(${t-~}) ${1-Enter}";printf "\r\e[K";}

readS () { reads "$@"; echo "$*";}

Post Reply