./configure : /bin/sh^M : bad interpreter

LinuxBashShellNewline

Linux Problem Overview


I've been trying to install lpng142 on my fed 12 system. Seems like a problem to me. I get this error

[root@localhost lpng142]# ./configure
bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory
[root@localhost lpng142]# 

How do I fix this? The /etc/fstab file:

#
# /etc/fstab
# Created by anaconda on Wed May 26 18:12:05 2010
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=ce67cf79-22c3-45d4-8374-bd0075617cc8 /boot                   ext4    
defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

Linux Solutions


Solution 1 - Linux

To fix, open your script with vi or vim and enter in vi command mode (key Esc), then type this:

:set fileformat=unix

Finally save it

:x! or :wq!

Solution 2 - Linux

Looks like you have a dos line ending file. The clue is the ^M.

You need to re-save the file using Unix line endings.

You might have a dos2unix command line utility that will also do this for you.

Solution 3 - Linux

Or if you want to do this with a script:

sed -i 's/\r//' filename

Solution 4 - Linux

Your configure file contains CRLF line endings (windows style) instead of simple LF line endings (unix style). Did you transfer it using FTP mode ASCII from Windows?

You can use

dos2unix configure

to fix this, or open it in vi and use :%s/^M//g; to substitute them all (use CTRL+V, CTRL+M to get the ^M)

Solution 5 - Linux

You can use following command to fix

cat file_name.sh | tr -d '\r' > file_name.sh.new

Solution 6 - Linux

If you could not found run the command,

CentOS:

# yum install dos2unix*

# dos2unix filename.sh
dos2unix: converting file filename.sh to Unix format ...

Ubuntu / Debian:

# apt-get install dos2unix

Solution 7 - Linux

This usually happens when you have edited a file from Windows and now trying to execute that from some unix based machine.

The solution presented on Linux Forum worked for me (many times):

perl -i -pe's/\r$//;' <file name here>

Hope this helps.

PS: you need to have perl installed on your unix/linux machine.

Solution 8 - Linux

Thanks to pwc101's comment on this post, this command worked in Kali Linux .

sed -i s/{ctrl+v}{ctrl+m}// {filename}

Make sure you replace the bits in brackets, {}. I.e. {ctrl+m} means press Ctrl key and the M key together.

Solution 9 - Linux

If you're on OS X, you can change line endings in XCode by opening the file and selecting the

View -> Text -> Line Endings -> Unix

menu item, then Save. This is for XCode 3.x. Probably something similar in XCode 4.

Solution 10 - Linux

Following on from Richard's comment. Here's the easy way to convert your file to UNIX line endings. If you're like me you created it in Windows Notepad and then tried to run it in Linux - bad idea.

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

Any other problems try this link.

Solution 11 - Linux

If you are using TextMate or a similar programme, do save as, and then in encodings choose LF instead of CRLF.

Solution 12 - Linux

When you write your script on windows environment and you want to run it on unix environnement you need to be careful about the encodage :

dos2unix $filePath

Solution 13 - Linux

Just adding sh before script name make it work in my case.

Solution 14 - Linux

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

dos2unix file_name

Solution 15 - Linux

You can also do this in Kate.

  1. Open the file
  2. Open the Tools menu
  3. Expand the End Of Line submenu
  4. Select UNIX
  5. Save the file.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVineeth PradhanView Question on Stackoverflow
Solution 1 - LinuxpolymameView Answer on Stackoverflow
Solution 2 - LinuxRichardView Answer on Stackoverflow
Solution 3 - LinuxSomaiah KumberaView Answer on Stackoverflow
Solution 4 - LinuxKonerakView Answer on Stackoverflow
Solution 5 - Linuxwu liangView Answer on Stackoverflow
Solution 6 - LinuxLakshmikandanView Answer on Stackoverflow
Solution 7 - LinuxAURView Answer on Stackoverflow
Solution 8 - Linuxbr3ntView Answer on Stackoverflow
Solution 9 - LinuxVern JensenView Answer on Stackoverflow
Solution 10 - LinuxzuallauzView Answer on Stackoverflow
Solution 11 - Linuxpatapouf_aiView Answer on Stackoverflow
Solution 12 - LinuxYoussouf MaigaView Answer on Stackoverflow
Solution 13 - LinuxSkorpENView Answer on Stackoverflow
Solution 14 - LinuxsrpatchView Answer on Stackoverflow
Solution 15 - LinuxTjaartView Answer on Stackoverflow