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?
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.
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.
/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.
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.
Remove ^M
control chars with
perl -i -pe 'y|\r||d' script.pl
/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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With