views:

457

answers:

3

When using Cygwin, I frequently copy a Windows path and manually edit all of the slashes to Unix format. For example, if I am using Cygwin and need to change directory I enter:

cd C:\windows\path 

then edit this to

cd C:/windows/path  

(Typically, the path is much longer than that). Is there a way to use sed, or something else to do this automatically? For example, I tried:

echo C:\windows\path|sed 's|\\|g'  

but got the following error

sed: -e expression #1, char 7: unterminated `s' command

My goal is to reduce the typing, so maybe I could write a program which I could call. Ideally I would type:

conversionScript cd C:/windows/path 

and this would be equivalent to typing:

cd C:\windows\path
+3  A: 

Read about the cygpath command.

somecommand `cygpath -u WIN_PATH`

e.g.

bmargulies
backticks were eaten by markdown syntax.
Pasi Savolainen
A: 

cmd.exe doesn't like single quotes. You should use double quotes

C:\test>echo C:\windows\path|sed "s|\\|/|g"
C:/windows/path
ghostdog74
+1  A: 

Thanks all. Apparently all I need are single quotes around the path:

cd 'C:/windows/path'

and Cygwin will convert it. Cygpath would work too, but it also needs the single quotes.

Jennette