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 am having trouble with running .sh script on Windows using Cygwin.

When i run the file: ./ -s srv.txt I am getting: ./ line 1: #!/bin/bash: No such file or directory

Can you guys help me what does that mean. The 1st line is commented :)


share|improve this question
Is bash in /bin? Is it executable (chmod +x /bin/bash)? – zero2cx Oct 5 '12 at 21:46
I did it, yeah which bash is giving /usr/bin/bash – elbek Oct 5 '12 at 21:46
up vote 3 down vote accepted

I had the same issue running cygwin under windows. For me, it had nothing to do with the path.

It had everything to do with the encoding. I was using UTF-8 with the BOM (Byte Order Mark). The BOM was causing it to choke. Once I removed it, it worked flawlessly.

I updated the encoding using Notepad++ by:

Encoding -> Encode in UTF-8 without BOM

The which bash command outputted:


However it was still able to resolve

share|improve this answer

It usually means there's a ^M (carriage return) at the end of each line of your file or some other encoding issue which prevents the #!/bin/bash line being interpreted correctly.

Take a copy of the file and save it as plain ASCII using an editor of your choice to remove as much non-ASCII encoding as possible. Also, try to save it in 'UNIX' format if the editor supports it.

share|improve this answer
What is vim? I have notepad++, I am on windows. – elbek Oct 5 '12 at 21:56
vim is a unix file editor, if the file won't run under Cygwin, the best bet is find out why under Cygwin. The problem is you're saving a windows file (which has carriage returns and linefeeds) and trying to run it under Cygwin. If you can, tell Notepad++ to save in 'unix' format. – EightBitTony Oct 5 '12 at 21:57
I did it, There is an option to make it UNIX format and I did it using notepad++ – elbek Oct 5 '12 at 21:59
Can you at least try what I suggest? Edit it in vim (in your Cygwin shell type, vim, and then type what I said, and see if the ^M symbols show up at the end of each line. – EightBitTony Oct 5 '12 at 22:00
Use this to see if you have the proper line endings: <pre>od -c</pre> This command shows exactly what characters are present. – UtahJarhead Oct 6 '12 at 1:03

Have you tried to run...


Instead of...


I'm not sure (I never ran Cygwin) but it seems that /bin/bash is not a path in your machine, so your shebang (#!/bin/bash) blows the program.

If you run the program using sh the shebang should be treated as a comment.

Hope this helps.

share|improve this answer

#!/bin/bash (called a shebang, short for Crash (#) Bang (!), tells the shell which program to use to execute the script in question. You'll see this with perl scripts (#!/usr/bin/perl), Python (#!/usr/bin/python), or php (#!/usr/bin/php) as well.

In your situation, a few things could be causing it. Either the 'bash' shell is not installed or the script is in an unrecognized format that you can't see.

First, does bash exist? Give us the results of this: ls -l /bin/bash

Second, what is in the script? Give us the first 2 lines of this: od -c What we're looking for is the script being in the wrong format. Windows likes CRLF'or \r\n for a line ending while Linux only likes LF or \n (see also:

To be honest, I don't know if CYGWIN likes Windows line endings or Linux, but that's a very likely cause for your issue.

Again, give us the output of od -c and we'll see what's up.

share|improve this answer

In the past I have had /M problems in python scripts written on a windows box and trying to use them on a linux box. I used dos2unix to convert the files to make them operable on the linux box. If carriage returns (or other windows text formatting issues) exist and are the cause of the problem this might help.

share|improve this answer

You must log in to answer this question.

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