Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am having trouble with running .sh script on Windows using Cygwin.

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

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

thanks.

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

5 Answers 5

up vote 2 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:

/usr/bin/bash

However it was still able to resolve

#!/bin/bash
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

Have you tried to run...

sh build.sh

Instead of...

./build.sh

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 build.sh 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: http://en.wikipedia.org/wiki/Newline)

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 build.sh and we'll see what's up.

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 build.sh), 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
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.