TMOUT within script file misbehaves for the select command. How to fix it?
1
vote
3
answers
432
views
**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
Asked by Grzegorz
(121 rep)
Jun 7, 2019, 06:58 PM
Last activity: Sep 5, 2020, 04:32 PM
Last activity: Sep 5, 2020, 04:32 PM