[prev in list] [next in list] [prev in thread] [next in thread]
List: bash-bug
Subject: Re: Puzzling discrepancy in bash variables
From: Larry Clapp <larry () theclapp ! org>
Date: 2008-10-16 13:06:56
Message-ID: 20081016130656.GG24298 () cupid ! theclapp ! org
[Download RAW message or body]
On Wed, Oct 15, 2008 at 03:11:15PM -0700, RMMM wrote:
> I'm trying to create a bash function for use in auto completion, but
> I've run into bash behavior I don't understand. All I want to do is
> generate a list of the file names from a certain directory. I have a
> line
>
> filenames=$(for file in `ls -1 mydir`; do echo -n "${file} " ; done )
>
> This seems to produce the correct list:
> bash> echo $filenames
> resources doc src
> bash>
>
> However, it doesn't work with the compgen function:
> bash> compgen -W "${filenames}" -- s
> bash>
>
> ????
>
> On the other hand, if I create the same variable manually, it works:
> bash> filenames1="resources doc src "
> bash> compgen -W "${filenames1}" -- s
> src
> bash>
>
> As far as I can tell, the variables $filenames and $filenames1 have
> the same values. Yet, they behave differently when used in an
> argument. Is there some hidden aspect to a bash variable that I'm
> not seeing?
Any chance you could skip the loop and the ls entirely?
lmc@cupid:~$ ls bash-test
doc resources src
lmc@cupid:~$ f=$(cd bash-test; echo *)
lmc@cupid:~$ compgen -W "$f" -- s
src
-- Larry
p.s. Disclaimer: I'm new to bash and don't have a good idea what
compgen is supposed to do, but it seems to pass your test case.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic