When have windows file version of shell script (*.sh) and want to execute it in Ubuntu/linux environment, sometimes we get this error:

Not able to execute a .sh file: /bin/bash^M: bad interpreter

It is happen because the ^M is a carriage return character. Linux uses the line feed character to mark the end of a line, whereas Windows uses the two-character sequence CR LF

One of the solution is, you can use sed command, sed will replace all the char/regex that you define on entire file. So, you can remove the CR with this command :

sed -i -e ‘s/\r$//’ file.sh

trying to be happy coding \(^^)/

credit : askubuntu, grymoire sed tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *

Set your Twitter account name in your settings to use the TwitterBar Section.