Re: need help with bash -c command with cygpath

2008-01-14 Thread Gary Johnson
On 2008-01-11, Jay wrote:

 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).

Something I used to work around this problem was to have Windows 
invoke a bat file and have that bat file invoke bash.  The key, 
though, suggested in this list some time ago, is to add noglob to 
the CYGWIN environment variable in the bat file, so that the bat 
file can pass the file name, directory name, or network path given 
to it by Windows to the bash command unchanged.  E.g.,

   set cygwin_save=%CYGWIN%
   set CYGWIN=%CYGWIN% noglob
   C:\cygwin\bin\rxvt.exe -e C:/cygwin/bin/bash --login -c run_bash_here 
'%1' '%cygwin_save%'

where run_bash_here is a function defined in ~/.bashrc that 
contains, among other things,

# Restore original value of CYGPATH.
#
CYGWIN=$2

Regards,
Gary


--
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/



RE: Re: need help with bash -c command with cygpath

2008-01-11 Thread Phil Betts
Jay wrote on Friday, January 11, 2008 3:14 PM::

 That's still somewhat wasteful, starting bash just to get a vim
 alias - why not use the full name gvim, and bypass the bash process
 to begin with? 
 
 you right, i'm going to remove it, thanks.
 
 My main problem now is that for some reason the leading backslash on
 UNC names is getting dropped when calling bash -c from the windows
 command prompt, even when using just single quotes.  So if you run
 this from a windows command prompt: 
 
 H:\C:\cygwin\bin\bash -v -c '\\UNC_PATH\Dir'
 \UNC_PATH\Dir   --Leading backslash dropped
 /usr/bin/bash: UNC_PATHDir: command not found
 
 It drops off the leading backslash.
 
 When you run it from Cygwin bash:
 bash -v -c '\\UNC_PATH\Dir'
 \\UNC_PATH\Dir   --The leading backslash is preserved.
 bash: \UNC_PATHDir: command not found
 
 I know i can make it work by piping the path into sed, but I'm just
 wondering why i'm losing the leading backslash when running from
 windows. 
 
 Maybe dos is passing in the single quotes as double quotes.
 

dos (i.e. cmd.exe) does not have the same quoting rules as bash,
so \\ inside single quotes means the same as it does inside double
quotes in bash.

Why are you even trying to use backslashes?  There's no need (even
in cmd.exe), but there's certainly no point in using them in a posix
command.  Just replace all backslashes with forward slashes and you've
sidestepped the problem.

If you absolutely MUST have backslashes, from cmd.exe, you need to 
double each backslash:

H:\C:\cygwin\bin\bash -v -c 'UNC_PATH\\Dir'

(actually only the first really needs to be doubled, because \ has
no special meaning if it's followed by a letter)

Phil

--
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/



Re: Re: need help with bash -c command with cygpath

2008-01-11 Thread Jay
 H:\C:\cygwin\bin\bash -v -c 'UNC_PATH\\Dir'
 
 (actually only the first really needs to be doubled, because \ has
 no special meaning if it's followed by a letter)
 
 Phil
 
 

I'm getting the path from the registry via a right click menu and passing it
into the bash -c command.  
But the leading slash is getting removed on UNC paths.  
I think i'm going to have to sed it.








--
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/



Re: need help with bash -c command with cygpath

2008-01-11 Thread Jay
 That's still somewhat wasteful, starting bash just to get a vim alias -
 why not use the full name gvim, and bypass the bash process to begin with?

you right, i'm going to remove it, thanks.

My main problem now is that for some reason the leading backslash on UNC names
is getting dropped when calling bash -c from the windows command prompt, even
when using just single quotes.  So if you run this from a windows command 
prompt:

H:\C:\cygwin\bin\bash -v -c '\\UNC_PATH\Dir'
\UNC_PATH\Dir   --Leading backslash dropped
/usr/bin/bash: UNC_PATHDir: command not found

It drops off the leading backslash.

When you run it from Cygwin bash:
bash -v -c '\\UNC_PATH\Dir'
\\UNC_PATH\Dir   --The leading backslash is preserved.
bash: \UNC_PATHDir: command not found

I know i can make it work by piping the path into sed, but I'm just wondering
why i'm losing the leading backslash when running from windows.

Maybe dos is passing in the single quotes as double quotes.

Thanks again for the help.


--
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/



RE: Re: need help with bash -c command with cygpath

2008-01-11 Thread Dave Korn
On 11 January 2008 15:51, Phil Betts wrote:

 If you absolutely MUST have backslashes, from cmd.exe, you need to
 double each backslash:
 
 H:\C:\cygwin\bin\bash -v -c 'UNC_PATH\\Dir'
 

  That doesn't work for me.  Adding the '-x' option to bash is very handy for
debugging these sorts of problems, it shows you what bash thinks it's actually
seeing:-


C:\Documents and Settings\dkC:\cygwin\bin\bash -v -x -c 'UNC_PATH\\Dir'
\\UNC_PATH\Dir
+ '\UNC_PATHDir'
/usr/bin/bash: \UNC_PATHDir: command not found


  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\dkC:\cygwin\bin\bash -v -x -c 'UNC_PATH\\Dir'
'\\UNC_PATH\Dir'
+ '\\UNC_PATH\Dir'
/usr/bin/bash: \\UNC_PATH\Dir: command not found

C:\Documents and Settings\dk


  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'

(just using this example to illustrate how the outer quotes protect the bash
commandline from cmd, and the inner quotes are part of the bash commandline).

cheers,
  DaveK
-- 
Can't think of a witty .sigline today


--
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/



Re: need help with bash -c command with cygpath

2008-01-11 Thread Eric Blake

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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\dkC:\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_PATHDir

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 \).

- --
Don't work too hard, make some time for fun as well!

Eric Blake [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHh+Ce84KuGfSFAYARAkhJAKCnk3p+yhal3k/09fAKywhficzz0ACgi+TA
hVScKscjLyeHoc2Vx6LYiWM=
=eSTr
-END PGP SIGNATURE-

--
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/



Re: need help with bash -c command with cygpath

2008-01-11 Thread Jay
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\dkC:\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_PATHDir
 
 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/



Re: need help with bash -c command with cygpath

2008-01-09 Thread Jay
 Whoa - it seldom makes sense to use -i and -c simultaneously - what good

What i'm actually trying to do is have a right-click menu in windows so that
when i right click on a file i can choose head from the context menu, and it
will send the top 10 lines of the file to vim.  I have gvim (windows version)
aliased in my .bashrc so that's why i'm using the -i switch.

What i have done is created the following registry key:
[HKEY_CLASSES_ROOT\*\shell\Head\Command]
with the (default) value set to: 
C:\CYGWIN\bin\bash -i -c head $(cygpath -a '%1') | vim -R -

This works perfectly for local files, but does not work at all for network
shares via UNCs due to the problem stated earlier.

 bash -c cygpath -a ''\\uncpath\mydrive$'\'

This works! but i can't figure out how to make it work for this scenario

bash -i -c head $(cygpath -a 
'\\gandy1\rjapps$\Subsidiarypayroll\Web.config'')

Maybe i have the quotes messed up, or maybe i'm going about doing this all 
wrong.

 By the way, none of this tutorial on shell quoting is cygwin specific.

Thanks again for the help.  






--
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/



Re: need help with bash -c command with cygpath

2008-01-09 Thread Eric Blake

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Jay on 1/9/2008 7:13 AM:
| Whoa - it seldom makes sense to use -i and -c simultaneously - what good
|
| What i'm actually trying to do is have a right-click menu in windows so that
| when i right click on a file i can choose head from the context menu, and it
| will send the top 10 lines of the file to vim.  I have gvim (windows
version)
| aliased in my .bashrc so that's why i'm using the -i switch.

That's still somewhat wasteful, starting bash just to get a vim alias -
why not use the full name gvim, and bypass the bash process to begin with?

|
| What i have done is created the following registry key:
| [HKEY_CLASSES_ROOT\*\shell\Head\Command]
| with the (default) value set to:
| C:\CYGWIN\bin\bash -i -c head $(cygpath -a '%1') | vim -R -

Why didn't you say so in the first place?  Windows registry quoting rules
are different than bash quoting rules.  And now you are getting into the
realm of cygwin applicability.  You may be interested in examining how the
cygwin package chere solves this same sort of problem.

Your biggest problem is that you want a single argument passed to -c, but
which contains proper quoting rules for bash.  In isolation, you want the
above command to look like:

bash -c 'head $(cygpath -a '%1') | vim -R -'

So now you have to figure out the escape sequences to get

'head $(cygpath -a '%1')'

stored into the registry - probably something like (untested):

'head $(cygpath -a '%1')'

or

'head \$(cygpath -a '%1')\'

| Maybe i have the quotes messed up, or maybe i'm going about doing this
all wrong.

It's all in the quoting.

- --
Don't work too hard, make some time for fun as well!

Eric Blake [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHhNk884KuGfSFAYARAg7ZAKDGWpkFVfkFQtLOzBD6EFv9Lfz2QwCg1uOB
tTwXD3Bts5S5tFX74c5U/nw=
=MZLe
-END PGP SIGNATURE-

--
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/



need help with bash -c command with cygpath

2008-01-08 Thread Jay
When i run
cygpath -a '\\uncpath\mydrive$'
//uncpath/mydrive$

Which is the expected behaivor.

When i run
bash -i -c cygpath -a '\\uncpath\mydrive$'
/C/uncpath/mydrive$

Which is not what i want.  I'm trying to pass in the unc path from windows, so
it needs converted.

Why do i get different results depending on how it is called? 

Thanks in advance.

Jay.


--
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/



Re: need help with bash -c command with cygpath

2008-01-08 Thread Christopher Faylor
On Wed, Jan 09, 2008 at 01:52:31AM +, Jay wrote:
When i run
cygpath -a '\\uncpath\mydrive$'
//uncpath/mydrive$

Which is the expected behaivor.

When i run
bash -i -c cygpath -a '\\uncpath\mydrive$'
/C/uncpath/mydrive$

Which is not what i want.  I'm trying to pass in the unc path from windows, so
it needs converted.

Why do i get different results depending on how it is called? 

It's because of the way the backslash is handled within double quotes.

info bash may be of some help.

cgf

--
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/



Re: need help with bash -c command with cygpath

2008-01-08 Thread Jay
 It's because of the way the backslash is handled within double quotes.
 
 info bash may be of some help.
 
 cgf
 
 

Thanks for the help.  I read the info.  Looks like i will have to pass the UNC
path into a script and do the work there.

Thanks again.



--
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/



Re: need help with bash -c command with cygpath

2008-01-08 Thread Eric Blake

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

According to Jay on 1/8/2008 6:52 PM:
| When i run
| bash -i -c cygpath -a '\\uncpath\mydrive$'

Whoa - it seldom makes sense to use -i and -c simultaneously - what good
is an interactive shell, if all it is going to do is execute a single
command sequence that works just fine non-interactively?  Drop the -i.

For that matter, why do you need to invoke another instance of bash to
call cygpath, when you've already stated that cygpath works just fine on
its own?

| Why do i get different results depending on how it is called?

Because you are calling it differently.  Try:

echo bash -i -c cygpath -a '\\uncpath\mydrive$'

to see what you were calling, and note that it wasn't a UNC path.  In
bash,  and '' don't nest.  Therefore, the rules for  apply, since that
is your outer quoting, and \\ simplifies to \, \m happens to pass
unchanged, and $' happens to pass unchanged (but other sequences would
have led to other surprises).

This is one way to do what you seem to want:

bash -c cygpath -a ''\\uncpath\mydrive$'\'

By the way, none of this tutorial on shell quoting is cygwin specific.

- --
Don't work too hard, make some time for fun as well!

Eric Blake [EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHhFWT84KuGfSFAYARApImAJsENqjN54AbhvIP1uX6CgYHO5gZgwCgtOV4
lKmUlY5zgUsZGjWBt/aOPbw=
=F3eB
-END PGP SIGNATURE-

--
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/