Sunday, January 17, 2010

cygpath quoting for directories with spaces in their name

Had to experiment with quoting with cygpath to patch up some scripts under cygwin.
I was trying to properly quote an environment variable defined on the Windows side: 
MSSDK=C:\Program Files\Microsoft SDKs\Windows\v7.0


  • Just using

    cygpath –u $MSSDK

    resulted in a multi-line return of:

    C:/Program
    Files/Microsoft/
    SDKs/Windows/v7.0



  • cygpath –u “$MSSDK”

    returned a single line:

    /cygdrive/c/Progarm Files/Microsoft SDKs/Windows/v7.0


  • and finally

    echo \”`cygpath –u “$MSSDK”`"\” 

    returned the directory properly quoted:

    “/cygdrive/c/Program Files/Microsoft SDKs/Windows/v7.0”


Hurray. Back to script editing…

1 comment:

Mark Statkus said...

Thanks I similarly had to adjust this for babun since I had a space in my user folder when referencing a core.editor to sublime.

#!/bin/bash
"/cygdrive/c/Program Files/Sublime Text 3/subl.exe" -w -n "`cygpath -d -w "$@"`"


That helped me get around the path issues.