Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a Windows path to a Unix path on Cygwin command line

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
like image 480
Jennette Avatar asked Apr 14 '10 22:04

Jennette


People also ask

How do I change the PATH in Cygwin?

Update the PATH environment variable: From the Start menu, select Parameters > Control Panel > System. Select the Advanced tab and click Environment variables. Edit the PATH environment variable to add the Cygwin installation directory, for example c:\cygwin\bin; and click OK.

How use Cygwin terminal in Windows?

Go to http://cygwin.com and click on "Install Cygwin" in the left column. This will allow you to download a setup.exe file and choose "Install from Internet." Click "Next." Choose your settings. For most users, it is fine to leave the default installation directory, which is "c:\cygwin\ and the other default settings.

Where is Cygdrive on Windows?

Using Cygwin As noted, Cygwin provides a Unix-like environment under Windows. The installation directory (by default, c:\cygwin) is the root of the Unix-like file system, which contains bin, etc, home, tmp, and usr directories as would be found on a GNU/Linux or other Unix system.

What is Cygpath?

The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style pathnames and vice versa. It can be used when a Cygwin program needs to pass a file name to a native Windows program, or expects to get a file name from a native Windows program.


2 Answers

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 to prevent the shell from eating the backslash characters.

like image 110
Jennette Avatar answered Nov 05 '22 09:11

Jennette


Read about the cygpath command.

somecommand `cygpath -u WIN_PATH`

e.g.

like image 41
bmargulies Avatar answered Nov 05 '22 10:11

bmargulies