This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bash puzzle: Spaces, environment variables and tab completion


You're swimming upstream. Don't do that. Use the system in accordance with its design.

Parsing command lines based on white-space separators fundamentally entails the need for escaping or quoting when those separator characters are to be included in the arguments and not used to separate them.

At 22:09 2002-12-03, James Shaw wrote:
Hi everyone,

I have been using cygwin for several months, and there is something that I haven't been able to figure out how to do: effectively use spaces in bash environment variables.

I realize this is basically a bash question and isn't Cygwin specific, but I'm sure more Cygwin users have to deal with spaces in bash than the typical bash user.

What I want to do is define an environment
variable so I can easily cd or ls. E.g.
% PF="/cygdrive/c/Program Files"
% cd $PF
% ls $PF/Games
% ls $PF/G<tab completion!>

The above is close, I can
% cd "$PF"; ls "$PF"/Games; and even
ls "$PF"/G<tab> however, the quotes are clunky.

My kludge to avoid the quotes is:

% PF2="/cygdrive/c/Program?Files"

which allows cd $PF; ls $PF/Games,

but stops bash in its tracks on tab completion.

Since I would find this very handy, I've spent some time on trying to make this work. I've tried various quoting schemes, but with no luck.

So, I ask the list:
Can you define $PF so that cd $PF;
ls $PF/Games; and ls $PF/G<tab> all work???
No, No and Yes. Just leave the spaces in the variable and command completion will insert the necessary escapes when expanding it. If the variable references is already inside a double-quote (even if it's not yet closed on the right), then command completion will not insert the backslashes.

I usually like to puzzle these out for myself, but in this case, I'm stumped.

Thanks for your help,

Randall Schulz
Mountain View, CA USA

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]