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 new to using Cygwin, so apologies if this is a very newbie question.

I have a bash script where I "cd" to a directory then do something in that directory. However, the cd command fails with "No such file or directory /c/code/blah/blah".

If I copy the cd line directly into the shell prompt, then it works fine. It just fails in the script.

[edit] As requested, I've added the actual lines from the script:

cd /c/Code/Project

Thankyou for any help with this,

share|improve this question
Can you post the actual line(s) from the script? – Dennis Williamson Sep 16 '10 at 10:37
up vote 15 down vote accepted

What kind of line endings does your script have? For Cygwin bash script to work properly (without having to set special options), it must have Unix line endings (LF) rather than DOS line endings (CR-LF). If you saved the script with DOS line endings, bash will see your argument to cd as /c/Code/Project^M, where ^M is a CR, and won't find a directory by that name.

To see which kind of line endings it has, you can execute file scriptname, where scriptname is the name of your script. To convert the script so that it has Unix line endings, execute d2u scriptname.

Don't use Notepad to edit Cygwin bash scripts. It always saves files with DOS line endings.

share|improve this answer
Aha! That was it. I was using Vim to edit it. Thankyou :-) – Dan Sep 16 '10 at 15:33
Vim will work fine. It automatically detects whether files have Unix or DOS line endings and will save them the same way. By default, Cygwin's vim will create new files with Unix line endings, but Windows' gvim will create new file with DOS line endings. You can change that. See :help ff and :help ffs. – garyjohn Sep 16 '10 at 18:46
Emacs was also saving with CR-LF. Changing the line-ending style in-editor: – jfklein Nov 27 '14 at 4:34

You might find your files in /cygdrive/c...

share|improve this answer


cd /cygdrive/c/code/blah/blah

share|improve this answer
That will work for 'cd c:/code/blah/blah' not for 'cd /c/code/blah/blah'. Also, the 'c:' form works from a script too; Something else is missing here, the question needs more elaboration. – nik Sep 16 '10 at 11:39
This didn't work. – Dan Sep 16 '10 at 12:08
@nik the c: form didn't work either. Nothing I try works from a script. They all work from the command line. – Dan Sep 16 '10 at 13:03

Unless you override, a script executes in its own copy of the shell (usually Bash). Then when the script exits, that instance of bash also exits. So your script CDs into a new directory and then exits, returning you to the original Bash--which never did a CD.

Two ways to work around it. You can use an alias instead of a script, e.g. in your .profile have

alias mycd="cd /c/Code/Project"

Another way is to tell Bash not to spawn a subshell by using the "dot" syntax

. myscript
share|improve this answer
You've misread my question. The error message I asked about is written to the stdout by the cd command, which is within the script. I'm not asking for the current directory to have been changed once the script exits. – Dan Sep 16 '10 at 15:30

I don't have reputation to comment or vote but CarlF's answer helped me.

"So your script CDs into a new directory and then exits, returning you to the original Bash--which never did a CD."

Same script, but in my case, no error message.

This worked for me:


share|improve this answer

You must log in to answer this question.

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