UPDATE - looks like this is something peculiar with bash 4.3.42 as it works fine with 4.3.46. Leaving this post for those who run into the same issue in future.
When I run this command in bash command line it works properly:
% (TMOUT=3; s="no selection"; select s in a b c ; do break ; done; echo $s)
1) a
2) b
3) c
#?
no selection
% _
Result: displays no selection and comes back to command line.
When, however, I place it a script, and execute it, it repetitively requests selection.
% cat a.sh
#!/bin/bash
(TMOUT=3; s="no selection"; select s in a b c ; do break ; done; echo $s)
% ./a.sh
Result:
1) a
2) b
3) c
#? 1) a
2) b
3) c
#? 1) a
2) b
3) c
#? ^C
% _
Why it so? My main question is - how to make it work in a script?!
UPDATED
% bash --version
GNU bash, version 4.3.42(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
% uname
Linux lx1 2.6.32-642.6.2.el6.x86_64 #1 SMP Mon Oct 24 10:22:33 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
bash --version
)? – terdon♦ Jun 7 '19 at 19:14select
not terminating properly whenTMOUT
was set, but that's older than thebash
you're using. – Kusalananda♦ Jun 7 '19 at 20:51