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


At 22:01 2002-12-04, James Shaw wrote:
Hi all,

Thanks to everyone for the advice.

The first posts of advice were that it wasn't possible to do within the bash quoting mechanism:

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

I agree that I felt like I was swimming upstream. Hence my post. I do find it a little odd, because if I type into the command line: % cd /cygdrive/c/Program\ Files/G<Tab> it will work. But I seem to have no means to define an alias/macro/variable to exactly equal '/cygdrive/c/Program\ Files' _and_ be expanded before (and therefore available) to tab completion.
As Gary and I mentioned, you can use a variable containing the unescaped name of a file system entity even if it contains spaces. You can use or omit quote marks around the argument and command completion will use backslash escapes as needed.

Although I appreciate Gary's encouragement, going around bash instead of struggling with it, does seem the better solution. There were several variations on the same theme on this bypass solution. Thanks to Ehud, Michael and Igor. Basically either symbolically link or mount a (non spaced) file to the problem path. Then I can define an environment variable to that link/mount.

I've been playing around with these suggestions today and this solution does work! Puzzle solved. (Or at least worked around.)

Some notes:
Contrary to my expectations (and Randall's post), ls -L isn't needed. I can ls ~/pf, and it will deref the symlink and list the contents of c:/Program Files. And ls isn't aliased to ls -L. Any thoughts on why this is?
You'll need it if you include the "-l" option.

One minus with this 'cheat' is that I don't get the 'real' name of the path. E.g. If I cd ~/pf, bash (correctly) thinks that I'm in /home/jhs/pf, but it would be nice to use the long name. If it was a hard link, neither link would be the "real" name, but with a symlink, there is some sense of "real" and "virtual". So, if anyone has a fix for this minor glitch, I'd appreciate comments.
You can always use the "pwd" _program_ instead of the pwd shell built-in. Use "/bin/pwd"; an alias or shell procedure can make this easy to type. I have a shell procedure "wd" that prints both if they're different. The pwd program knows not of how you got to the current directory (whether symlinks were involved), it will trace the path back to the root and show the directory constructed that way.

This isn't that important for me since the main reason I have these aliases is to pop open windows explorer with the path in question. I find it very handy when in a cygwin shell to open an 'explorer' window in my current directory, so I wrote a little Perl script to cygpath a directory and call explorer. This is especially useful to copy from one open cygshell to another or to throw stuff in the Recycle Bin (rather than rm, if I'm feeling skittish). I find this command useful to navagate my windows world via cygwin and if there's any interest, I'd be happy to post the details.
Learn about "cygstart" and you won't have to script these things yourself. If the target is a directory, you get a Windows Explorer window. Other targets are processed in accordance with the handler associated with the object (for files, its the extension, of course). If you include the "-x" option (eXplore) you get the left-hand directory tree pane in the window.

Finally, I didn't try mount, since symlinking worked. I think that I've read that for cygwin, mount is faster (perhaps the mount table is in memory while the sym link is on disk?), but I sort of feel that mount is a superuser command and, even though I'm the only user, I like to stick to non-superuser solutions if available.

Again, thanks to everyone who helped.
We aim to please!


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]