solving spaces in paths in cygwin
Occasionally one has to share scripts and such that for convenience Windows users for their part would run in a Cygwin bash prompt, whilst others enjoy the nativeness of Linux etc. One issue is the use of variables to set program names up for use within those scripts. Windows + Cygwin users have no doubt at some point been a victim of spaces in file paths causing the executable files to not be found.
For example anything in 'Program Files' can not be found even from within Cygwin. Lets take something with two such spaces in its path as it will be handy in our examples later on.
Windows: C:\Program Files\CollabNet\Subversion Client\svn.exe
Cygwin: /cygdrive/c/Program Files/CollabNet/Subversion Client/svn
in Cygwin 'which svn' will find the full Cygwin Path as shown above, however, the program using such will only see
/cygdrive/c/Program
and nothing else. So this is a problem not only for our installed subversion client, but also any other that are normally installed in 'Program Files'
There are a few workarounds, including hard coding paths instead of using shelled commands to get the paths, this however deviates the shared scripts from what everyone else may be using quite happily.
The fix is , as usual, easy when you know how, and today I bothered to read docs and test a few things out, the solution I found best is the use of mount points.
There may be other users on the same computer using Cygwin also (not in my case but I did it this way anyway) so its always best to use a custom user oriented /etc/fstab.d/$username file.
here is my /etc/fstab.d/gmcdonald file:
C:/Program\040Files /programs ext3 binary 0 0
C:/Program\040Files/CollabNet/Subversion\040Client /programs/subversion ext3 binary 0 0
And that folks is all you need to do! Save that file (which you may need to create), from then on all your Program Files will be mapped to a path that cygwin can understand - /programs and /programs/subversion etc ..
using 'which svn' will correctly report /programs/subversion/svn and so your scripts will be able to find it too without issue.
FYI docs here: http://www.cygwin.com/cygwin-ug-net/using.html#mount-table
Enjoy