Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

helpmeman

macrumors newbie
Original poster
Feb 20, 2011
24
0
I have a file that I am trying to execute, but every time I try I get the following message: -bash: ./compile-scripts.sh: /bin/sh^M: bad interpreter: No such file or directory

This first line of the script I am trying to run is: #!/bin/sh

Any suggestions?
 
I have a file that I am trying to execute, but every time I try I get the following message: -bash: ./compile-scripts.sh: /bin/sh^M: bad interpreter: No such file or directory

This first line of the script I am trying to run is: #!/bin/sh

Any suggestions?

You many want to make sure that the file uses unix line termination. The ^M seems to imply that it may have been saved on a DOS/Windows PC with CR/LF line termination.

CR=^M LF=^J.
http://en.wikipedia.org/wiki/Carriage_return
http://en.wikipedia.org/wiki/Line_feed

B
 
What is the source of this file? Looks like it came from a DOS-y system. You can remove them like this:
tr -d '\r' < mySweetFile.sh > mySweetFileWithoutCRs.sh

-Lee
 
FWIW a strange habit I have.

I use zip/unzip to normalize line terminations.

I always have a copy of info-zip's implementation handy and converting an entire folder tree to the appropriate termination is as easy as

Code:
zip -mr zipname folder
unzip -a zipname

B
 
What is the source of this file? Looks like it came from a DOS-y system. You can remove them like this:
tr -d '\r' < mySweetFile.sh > mySweetFileWithoutCRs.sh

-Lee

It came from a DOS-y system I believe. I removed the CRs but it still didn't work. So I went through my /usrs/bin and I couldn't find sh (althought I found ssh)
 
It came from a DOS-y system I believe. I removed the CRs but it still didn't work. So I went through my /usrs/bin and I couldn't find sh (althought I found ssh)

As the error message implies it should be in /bin not /usr/bin or /usrs/bin or /users/bin.

Open terminal and type:

Code:
which sh

EDIT: Also check the contents of the file /etc/shells. Is /bin/sh listed?

How are you trying to launch your script?

B
 
I removed the CRs but it still didn't work.

Didn't work the same way, or didn't work in a different way?

The same way would mean you're getting the same error message that contains ^M. This suggests that you didn't actually remove the CRs from the file. The command line lee1210 gave produces a new file without CRs. The original file is unchanged.

A different way would mean you're getting a different error message. Post that error message.
 
Didn't work the same way, or didn't work in a different way?

The same way would mean you're getting the same error message that contains ^M. This suggests that you didn't actually remove the CRs from the file. The command line lee1210 gave produces a new file without CRs. The original file is unchanged.
Same way.

As the error message implies it should be in /bin not /usr/bin or /usrs/bin or /users/bin.

Open terminal and type:

Code:
which sh

EDIT: Also check the contents of the file /etc/shells. Is /bin/sh listed?

How are you trying to launch your script?

B

I am using terminal and I typed which sh and it returned /bin/sh and it was also listed in /etc/shells
 
Same way.

Post the output of this command sequence:
Code:
head -n 5 ./compile-scripts.sh | hexdump -C

Next, post the output of the same command sequence, but substitute the filename you used for mySweetFileWithoutCRs.sh in Lee's example.

Also post the output of this command:
Code:
ls -l

You can copy and paste commands into a Terminal window. Don't type them in manually.

If there are any errors, post the actual command you used, along with the actual error message.
 
The command line lee1210 gave produces a new file without CRs. The original file is unchanged.

That is actually why I started using the zip/unzip method especially when dealing with an entire folder or tree of mixed source files and binary files. It gives me the backup piece of mind and replaces the file(s) with the same name in the same place.

helpmeman it's helpful to actually copy and paste the command you entered and the output you receive in a code block. It may look like the same error to you, but not to us.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.