[Top][All Lists]

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

Puzzling discrepancy in bash variables

From: RMMM
Subject: Puzzling discrepancy in bash variables
Date: Wed, 15 Oct 2008 15:11:15 -0700 (PDT)

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 

However, it doesn't work with the compgen function:
bash> compgen -W "${filenames}" -- s


On the other hand, if I create the same variable manually, it works:
bash> filenames1="resources doc src "
bash> compgen -W "${filenames1}" -- s

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?

View this message in context: 
Sent from the Gnu - Bash mailing list archive at Nabble.com.

reply via email to

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