Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "bad interpreter: No such file or directory"

Tags:

sh

macos

perl

I'm trying to run a sh script and get the following error on Mac:

/usr/bin/perl^M: bad interpreter: No such file or directory 

How can I fix this?

like image 939
Elad Benda Avatar asked Jun 16 '13 07:06

Elad Benda


People also ask

How do you fix a bad interpreter?

Use the sed Command to Solve the /bin/bash^M: bad interpreter Error in Bash. The sed command-line tool performs text transformations on an input stream. You can remove the "\r" characters in the file with the command below. Now you can execute the file without error.

How do I fix bin bash'm a bad interpreter?

To fix the error in the Windows operating system, open the bash script file in the Notepad++ editor and then go to the preferences tab via the settings menu as below. Close the window after choosing Unix/OSX as the format. Afterwards, save and close the file.

What is bad interpreter?

/bin/bash^M: bad interpreter: No such file or directory ^M is a character used by Windows to mark the end of a line (so it is a carriage return) and that matches the CR character.

Why is there no such file or directory?

log No such file or directory” the problem is most likely on the client side. In most cases, this simply indicates that the file or folder specified was a top-level item selected in the backup schedule and it did not exist at the time the backup ran.


2 Answers

Remove ^M control chars with

perl -i -pe 'y|\r||d' script.pl 
like image 154
mpapec Avatar answered Sep 19 '22 02:09

mpapec


/usr/bin/perl^M:

Remove the ^M at the end of usr/bin/perl from the #! line at the beginning of the script. That is a spurious ASCII 13 character that is making the shell go crazy.

Possibly you would need to inspect the file with a binary editor if you do not see the character.

You could do like this to convert the file to Mac line-ending format:

$ vi your_script.sh 

once in vi type:

 :set ff=unix   :x 
like image 21
sergio Avatar answered Sep 19 '22 02:09

sergio