/bin/bash^M: bad interpreter

While trying to run a bash script I get the following error :/bin/bash^M: bad interpreter

Warning: I did edit the file in Windows with notepad.

If there a fix for this?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Linux and Windows handle the carriage return/line feed at the end of a line differently.  So, if you edit a file in Windows and then go back to Linux, you will find a ^M added to the end of each line.  There are a couple of ways to get rid of this:

If you have it, use the command dos2unix:
dos2unix yourscript.sh > yourscript2.sh

Using sed:
sed -e "s/^M//g" yourscript.sh > yourscript2.sh

In vi:

(Is this John Culkin from Scranton, PA?)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jculkincysAuthor Commented:
It sure is me.

Is this John Kanka aka webmaster of the greatest website in the world (http://kankasports.blogspot.com/ ) aka my idol

You are truly an EXPERT!!!
Why, it sure is me too.  I was wondering when I would run into someone I knew on here....

Are you dabbling in Linux for work or for fun?
jculkincysAuthor Commented:
Both - I am a sysadmin now - or at least thats what boss claims.

I dig bash and wish I was better at it

I'm stuck in a Windows environment, but I'd probably let batch files and VBS scripts do my entire job if I could get away with it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.