• Skip to primary navigation
  • Skip to main content
  • Skip to footer

JH Tech Services

A knowledgebase

  • Portfolio
  • Knowledgebase
  • About

Fixing Line Endings

May 8, 2008 by jer0dh

Getting error when running bash file in terminal. Something about bad interpreter /bin/sh^M

I knew it had to due to line endings between Windows and Linux. Found this cool command from Waldo at http://www.macosxhints.com


There are many places where PERL is incredibly handy. This is one of them. You can use
PERL on the command line to change the line ending ( a 'r' (Mac) to a 'n' (UNIX) ):

perl -pi -e 's/r/n/g'

I have put an alias in my .bashrc file that looks like this:

alias fle="perl -pi -e 's/r/n/g' "

Now I just type fle and everything works file. I use "fle" for "fix line endings," but
yo can use anything you want to.

Worked very well

  • Knowledgebase
  • Uncategorized

Footer

  • Portfolio
  • Knowledgebase
  • About

© 2023