This is the mail archive of the cygwin 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: need help with bash -c <command> with cygpath


Eric Blake <ebb9 <at> byu.net> writes:

> 
> 
> According to Dave Korn on 1/11/2008 9:38 AM:
> |   I believe what is needed is 1) outer double-quotes, for cmd's benefit, 2)
> | inner single-quotes, for bash's benefit, 3) double up the slashes /as well/,
> | because there's one more level of quoting being stripped than I can account
> | for, but anyway it works for me:
> |
> | C:\Documents and Settings\dk>C:\cygwin\bin\bash -v -x -c
> "'\\\\UNC_PATH\\Dir'"
> | '\\UNC_PATH\Dir'
> | + '\\UNC_PATH\Dir'
> | /usr/bin/bash: \\UNC_PATH\Dir: command not found
> 
> "'\\'" - the " quotes are stripped and \\ collapsed by cmd.exe => '\'
> '\' - the ' quotes are stripped by bash on execution => \
> 
> |   If I wasn't trying to execute a directory but list it instead, I'd say
> |
> | C:\cygwin\bin\bash -v -x -c "ls -la '\\\\UNC_PATH\\Dir'"
> 
> Which means:
> 
> bash -vxc "ls -la \\\\\\\\UNC_PATH\\\\Dir"
> 
> will also work (8 leading \ converted to 4 by cmd, then 4 converted to 2
> by bash, so that ls sees an argument with 2 leading \).

Thanks everyone for the help.  Since i'm getting the path from the registry i
can't add in the extra backslashes without using sed.  I ended up with this
registy key which seems to work for local drives as well as network drives
(UNCs) (haven't tested files with special characters).

(manually typed into the registry)
C:\cygwin\bin\bash -v -c "/usr/bin/head \"$(/usr/bin/echo '%1' | /usr/bin/sed
's#^\\\\\(\w\)#\\\\\\\\\1#;s#\\\#\/#g')\" | /cygdrive/c/John/Tools/vim/gvim.exe
-R -" 

Here is the regfile if anyone wants to try it out.  You will prob need to change
your path to gvim, or just use the path to cygwin vim.

--START REGFILE---
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Head2Vim]

[HKEY_CLASSES_ROOT\*\shell\Head2Vim\Command]
@="C:\\cygwin\\bin\\bash -v -c \"/usr/bin/head \\\"$(/usr/bin/echo '%1' |
/usr/bin/sed 's#^\\\\\\\\\\(\\w\\)#\\\\\\\\\\\\\\\\\\1#;s#\\\\\\#\\/#g')\\\" |
/cygdrive/c/John/Tools/vim/gvim.exe -R -\" "

--END REGFILE--
 




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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