RE: cygpath -u doesn't seem to convert spaces properly

2007-09-26 Thread Williams, Gerald S (Jerry)
Brian Dessent wrote:
 $ cd $ttt
 bash: cd: /cygdrive/c/Program: No such file or directory
 
 Yes, that's wrong.  [...] It's got nothing to do with
 cygpath and everything to do with proper portable scripting practice.

Quite true. When you're using bash or sh, you must *quote
your arguments* if they could possibly contain spaces or
other word separators. So learn to do it. Seriously, take
a few minutes and try it:

$ mkdir a b c
$ ABC=a b c
bash: cd: a: No such file or directory
$ cd $ABC
... etc.

If you don't want to have to quote variable expansions all
the time, use another shell. I know that zsh, at least,
doesn't require you to quote them. That being said, you
still should learn how to quote in a regular POSIX shell.
Portable shell scripts should really start with #!/bin/sh,
after all.

-gsw

--
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: cygpath -u doesn't seem to convert spaces properly

2007-09-26 Thread Jerome Fong

Thanks,

Jerome

Williams, Gerald S (Jerry) wrote:

Brian Dessent wrote:

$ cd $ttt
bash: cd: /cygdrive/c/Program: No such file or directory

Yes, that's wrong.  [...] It's got nothing to do with
cygpath and everything to do with proper portable scripting practice.


Quite true. When you're using bash or sh, you must *quote
your arguments* if they could possibly contain spaces or
other word separators. So learn to do it. Seriously, take
a few minutes and try it:

$ mkdir a b c
$ ABC=a b c
bash: cd: a: No such file or directory
$ cd $ABC
... etc.

If you don't want to have to quote variable expansions all
the time, use another shell. I know that zsh, at least,
doesn't require you to quote them. That being said, you
still should learn how to quote in a regular POSIX shell.
Portable shell scripts should really start with #!/bin/sh,
after all.

-gsw




--
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: cygpath -u doesn't seem to convert spaces properly

2007-09-25 Thread Thrall, Bryan
Jerome Fong wrote on Tuesday, September 25, 2007 6:23 PM:
 I am trying to use cygpath -u to convert my windows path to an unix
 path in my shell script.  However, it has problems with paths that
 has spaces in it.  For example, cygpath -u c:\Program Files\Java is
 converted to /cygdrive/c/Program Files/Java, which doesn't work.  Is
 there a flag that I am missing?
 
 I came up with the following, but it seems wrong.
 
 $ cygpath -u $(cygpath -m -s c:\Program Files\Java)
 /cygdrive/c/PROGRA~1/Java

WJFFM:

$ cygpath -u c:\Program Files\Java
/cygdrive/c/Program Files/Java
$ ls /cygdrive/c/Program Files/Java
j2re1.4.2  j2re1.4.2_04  jdk1.5.0_10  jre1.5.0  jre1.5.0_06
$ ls `cygpath -u 'c:\Program Files\Java'`
j2re1.4.2  j2re1.4.2_04  jdk1.5.0_10  jre1.5.0  jre1.5.0_06

Can you give specifics on how it doesn't work for you?
-- 
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]

--
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: cygpath -u doesn't seem to convert spaces properly

2007-09-25 Thread Brian Dessent
Jerome Fong wrote:

 I am trying to use cygpath -u to convert my windows path to an unix path
 in my shell script.  However, it has problems with paths that has spaces
 in it.  For example, cygpath -u c:\Program Files\Java is converted to
 /cygdrive/c/Program Files/Java, which doesn't work.  Is there a flag
 that I am missing?

The unix version is correct but still has spaces, which means it still
needs proper quoting.  So if you are doing something like this:

ls $(cygpath -u 'c:\Program Files\Java')

then you are not quoting sufficiently.  However, in your example below
you appear to be using the proper amount of quoting:

 $ cygpath -u $(cygpath -m -s c:\Program Files\Java)
 /cygdrive/c/PROGRA~1/Java

So please give us an example of exactly the command that fails, because
there should never be a need to resort to using the 8.3 short filename
ugliness -- especially since this is an optional NTFS feature that can
be disabled in order to speed things up, which means it's not entirely
portable (not to mention wholly unnecessary as long as proper quoting is
used.)

Brian

--
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: cygpath -u doesn't seem to convert spaces properly

2007-09-25 Thread Jerome Fong

It seems to be a quoting problem.   This is what I was doing:

$ ttt=$(cygpath -u $JAVA_HOME)

$ echo $ttt
/cygdrive/c/Program Files/Java/jdk1.5.0_10

$ cd $ttt
bash: cd: /cygdrive/c/Program: No such file or directory

$ cd $ttt

$pwd
/cygdrive/c/Program Files/Java/jdk1.5.0_10

Is is possible to setup the variable to not require the double quotes? 
  Since my other method doesn't require the double quotes, it would 
make the scripting much easier.  I wouldn't need to keep track of which 
variables I had to double quote.


$ =$(cygpath -u $(cygpath -m -s $JAVA_HOME))

$ echo $
/cygdrive/c/PROGRA~1/Java

$ cd $

$ pwd
/cygdrive/c/PROGRA~1/Java

Notice that I can use $ directly without have to use the double quote.

thanks,

Jerome

Jerome Fong wrote:
I am trying to use cygpath -u to convert my windows path to an unix path 
in my shell script.  However, it has problems with paths that has spaces 
in it.  For example, cygpath -u c:\Program Files\Java is converted to
/cygdrive/c/Program Files/Java, which doesn't work.  Is there a flag 
that I am missing?


I came up with the following, but it seems wrong.

$ cygpath -u $(cygpath -m -s c:\Program Files\Java)
/cygdrive/c/PROGRA~1/Java

Thanks,

Jerome





--
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: cygpath -u doesn't seem to convert spaces properly

2007-09-25 Thread Brian Dessent
Jerome Fong wrote:

 $ cd $ttt
 bash: cd: /cygdrive/c/Program: No such file or directory

Yes, that's wrong.  But more importantly, it's not wrong just in the
POSIX/Win32 path sense, it's wrong in the sense that it can't cope with
any argument that contains whitespace.  Your script would also fail on a
Linux system that for example had a directory like ~/some files -- and
in that case there is no 8.3 short filename hack to save you, so there
is no avoiding the need for proper quoting.  It's got nothing to do with
cygpath and everything to do with proper portable scripting practice.

 Is is possible to setup the variable to not require the double quotes?

Only if you neglect to support filenames and paths with spaces in them.

Since my other method doesn't require the double quotes, it would
 make the scripting much easier.  I wouldn't need to keep track of which
 variables I had to double quote.

Easier perhaps but still broken.

Brian

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