[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
possible compgen bug
From: |
Nicholas Mc Guire |
Subject: |
possible compgen bug |
Date: |
Fri, 9 May 2008 07:00:10 -0800 (AKDT) |
HI !
problem: compgen assigns first option on receiving an empty string as
input (i.e. by read -t 5 VAR timing out)
systems and OS:
X86 (Duron and Sempron)
Debian etch:
hofrat@backup:~/shell$ uname -a
Linux backup 2.6.18-hpt374 #4 SMP Thu Mar 20 00:07:28 CET 2008 i686
GNU/Linux
hofrat@backup:~/shell$ bash --version
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
Slackware 10.0:
root@rtl14:~/fipsi# uname -a
Linux rtl14 2.4.26 #6 Mon Jun 14 19:07:27 PDT 2004 i686 unknown unknown
GNU/Linux
root@rtl14:~/fipsi# bash --version
GNU bash, version 2.05b.0(1)-release (i486-slackware-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.
both systems show the same (supposedly wrong) behavior of the compgen
builtin function.
corect behavior:
----------------
when using read with a timeout and then evaluating a variable I get the
following expected behavior:
#! /bin/bash
read -p "timeout 5 > " -t 5 CMD
if [ "$CMD"x == exitx ] ; then
echo exiting
$CMD
elif [ "$CMD"x == quitx ] ; then
echo quite not a valid command calling exit with -1
exit -1
else
echo invalid command - exiting with -2
exit -2
fi
which gives me the expected response when it times out due to no input
hofrat@backup:~/shell$ ./1.sh
timeout 5 > invalid command - exiting with -2
hofrat@backup:~/shell$
probably errornous behavior:
----------------------------
when using compgen to allow shortcuts (in the below example for quit and
exit I get a strange behavior when no input is entered and write times
out after 5 seconds:
#! /bin/bash
read -p "timeout 5 > " -t 5 FOO
CMD=( $(compgen -W "quit exit" -- $FOO) )
if [ "$CMD"x == exitx ] ; then
echo exiting
$CMD
elif [ "$CMD"x == quitx ] ; then
echo quit not a valid command calling exit with -1
exit -1
else
echo invalid command - exiting with -2
exit -2
fi
hofrat@backup:~/shell$ ./2.sh
timeout 5 > quit not a valid command calling exit with -1
hofrat@backup:~/shell$
it seems to expand CMD to quit - not the behavior I expected
I assume that this is a bug in compgen as it indentifies an empty string
with the first word in the options passed - I would have expected it to be
a null-string (just as if one would type x, which has no match, thus the
null-string is assigned to CMD)
thx!
hofrat
- possible compgen bug,
Nicholas Mc Guire <=