Shell: Fixing shell script with ^M as carriage return character(s)

What appen ?

Running a shell (bash, sh, tcsh, or whatever) script fail with the error below

The source of the problem is that this file have been edited on Windows system (see below)

The ^M characters are carriage returns. Windows and DOS terminate lines of text with CR (^M, or ASCII code 13) followed by LF (^J, or linefeed, ASCII code 10). Linux uses just LF

if you edit this script vith vim in binary mode, you’ll see one or more ^M character(s)

$ vim -b script


Use the command tr

Use the command dos2unix

Use vi (or vim)

Open the script like this (don’t forget the -b option)

$ vim -b script

Enjoy !!!

One Response

Leave a Reply

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

Back to Top