Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get to grips with Bash scripting via Cygwin. My script is about as simple as it gets.

I change the directory to the root of my C drive, and print the new location.

cd /cygdrive/c

is saved in the file in my home directory. I then call ./ from the bash prompt. This results in the error

: No such file or directorygdrive/c
/cygdrive/c/Documents and Settings/rcotton

I definitely have a C drive, and the command cd /cygdrive/c works when I call it directly from the bash prompt.

I realise that this problem is likely stupidly simple; please can you tell me what I'm doing wrong.

share|improve this question
up vote 7 down vote accepted

Just in case you have edited your script with an editor which is not part of the Cygwin environment (e.g., anything like 'Notepad*', 'WordPad', etc.): convert your script to Unix-lineendings via the 'dos2unix' tool.

The script itself is absolutely correct, no need for any / or \ changes. The error message

: No such file or directorygdrive/c

leads me to think of problems with the lineending since \r\n (Windows line ending). Just in case you do not have 'dos2unix' installed:

tr -d \\r < win.txt > unix.txt


sed -e 's/$/\r/' < unix.txt > win.txt
share|improve this answer
Very well called. It was sneaky carriage returns causing the weirdness. – Richard Cotton Mar 22 '10 at 13:11

Are you sure you're using forward slash, and not backslash, in your cd command? Your problem would be symptomatic of mistaking these two.

Try these variants if just a single forward slash produces is indeed there and produces this weird error:

cd //cygdrive//c


cd \\cygdrive\\c
share|improve this answer
cd //cygdrive//c gives the error : No such host or network pathrive//c. cd \\cygdrive\\c gives the same error as before. – Richard Cotton Mar 22 '10 at 12:38

Try #!/usr/bin/bash.exe and see if that makes a difference. Either works on my Cygwin install, but the file is actually named bash.exe.

share|improve this answer

TO: ttarchala (and Mr Cotton)

In cygwin, //start1/path_2/stuff/long triggers UNC hack mode, which treats start1 as a SMB server with share path_2. This is not what was intended.

This will sometimes bite you in certain shell scripts that are shared with UNIX, where multiple forward slashes are always coalesced to a single slash. In cygwin, multiple forward slashes are coalesced EXCEPT if it's the beginning one, which is UNC trigger mode.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .