bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: possible compgen bug


From: Nicholas Mc Guire
Subject: Re: possible compgen bug
Date: Mon, 12 May 2008 22:39:23 -0800 (AKDT)

> Nicholas Mc Guire wrote:
>
> > 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)
>
> When it is not supplied any word to complete, compgen displays all
> possible completions -- in this case, the words supplied to `-W'.  This
> is what happens when you perform filename completion after no characters
> have been typed, for instance.  You can see this by running the compgen
> command:
>
> $ compgen -W "quit exit" -- $FOO
> quit
> exit
>
>
> Since the assignment to CMD makes it an array, it as if you assigned
> CMD=(quit exit).
>
> You use $CMD in the rest of the script, which is the same as ${CMD[0]},
> or `quit'.
>
ok - sorry for filing this as bug-report - I did reread the manpage of
bash a few times and we discussed it here with the obviously wrong
conclusion that this is a incorect/unexpected behavior.

thanks for the clarification !!

hofrat





reply via email to

[Prev in Thread] Current Thread [Next in Thread]