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

Sometimes when you take a file from a DOS/Windows system and move it to a Linux or Unix system you will get bash /bin/sh^M: bad interpreter: No such file or directory

DOS uses a carriage return (^M) with a line feed therefore linux system confused and thinks the script should be executed by /bin/bash^M which doesn’t exist.

Solution:

Option 1:

Install dos2unix and convert the file
Use the dos2unix command in linux to convert the saved file. example :

dos2unix file_name

Note: If its is not installed then
use yum install dos2unix

dos2unix Zip_Remove_CV.sh

Option 2:

vi and vim will convert line endings when you specify the file format.

vi myscript.sh

Hit ESC to enter command mode where you can set the format and save your changes.

:set fileformat=unix

:x!

Option 3:

sed is handy for cleaning up things like this from the command line.

sed -i ‘s/r//’ myscript.sh

Download and install yourself a copy of Notepad++ (free).
Open your script file in Notepad++.
File menu -> Save As ->
Save as type: Unix script file (.sh;.bsh)
Copy the new .sh file to your Linux system
Maxe it executable with: chmod 755 the_script_filename
Run it with: ./the_script_filename


Discover more from PlusDigit

Subscribe to get the latest posts sent to your email.

Discover more from PlusDigit

Subscribe now to keep reading and get access to the full archive.

Continue reading

AdBlock Detected!

Please disable your AdBlocker to access this website.

Once disabled, this message will disappear automatically.