[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bash enhancement to "select"]
From: |
bs |
Subject: |
[Bash enhancement to "select"] |
Date: |
Fri, 20 Oct 2000 22:54:54 +0200 |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -I. -I.
-I./include -I./lib -I/usr/local/include -g -O2
uname output: Linux firestar 2.2.17 #3 Tue Sep 26 15:44:50 SAST 2000 i686
unknown
Machine Type: i686-pc-linux-gnu
Bash Version: 2.04
Patch Level: 0
Release Status: release
Description:
[The 'select' function does not have a timeout. And the default
behaviour of the [return] key is painfull in the sense
that it just loops. The 'select' function is beautiful
for selecting on data who's size and quantity you don't
know - however if you have a default value - and want
to choose *that* on a simple [Return] - you can't -
you have to retype a selection. Painful. The 'READ'
function now has some beautiful args - eg Timeout
(-t xx) and Length (-n xx). It would be most ideal if
'select' could use them too - after all 'select' does
use the 'builtin-read' !!!! - and one more arg to change
the behavior in which 'select' deals with just a [return]
being pressed]
Repeat-By:
[
select fname in /tmp/*
do
echo you picked $fname \($REPLY\)
break
done
]
Fix:
[
To fix the pain of "Return" -
execute_cmd.c - line 1825
****************
repl_string = get_string_value ("REPLY");
if (*repl_string == 0)
{
/* MJE * continue; */
reply=0;
return "";
}
****************
ie - change the 'continue' into a 'return "null string"'. I'm not
sure what 'Posix' states - but to get the old effect put the
whole 'select' into a 'while' loop and 'continue' if '$REPLY'
has a 'null' value.
================================================================
To add a timeout in the 'select', we created a new shell variable
'READTMOUT'... and fooled around with some appropiate values.
builtins/read.def - line 143
****************
/* *MJE* IF READTMOUT is unset, we use the default of "-1". */
var = find_variable("READTMOUT");
if (var && var->value) tmout = atoi(var->value);
if (tmout < 1 || tmout > 10000000) /* ie - a stupid value */
tmout = -1; /* no timeout */
****************
Yup - Ugly - but the shell scripting works beautifully...
I know they are not proper context diffs - but only two small changes
:-)
All changes done by Mark J Elkins. <mje@posix.co.za>
]
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bash enhancement to "select"],
bs <=
- Prev by Date:
Re: :(){ :|:&};: in bash causes systemchrash
- Next by Date:
[Follow up on 'printf']
- Previous by thread:
B,U.I-L,D. -Y,O.U- ,C.A-B,L.E- ,B.O-X, .D-E`S`C`R`A`M`B`L`E`R,`,`,`, 2811
- Next by thread:
[Follow up on 'printf']
- Index(es):