LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-18-2008, 02:38 AM   #1
Stevie-B-242
LQ Newbie
 
Registered: Oct 2005
Posts: 9

Rep: Reputation: 0
Another simple question - cannot execute scripts


When I try to execute any of a number of scripts on my system (RHEL 5 - i386), I get the following error message:

-bash: ./simple_script: /bin/bash^M: bad interpreter: No such file or directory

What does this error mean and more importantly, how do I correct this issue?

Thanks!
--Steve
 
Old 02-18-2008, 02:52 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,791

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
Quote:
-bash: ./simple_script: /bin/bash^M: bad interpreter: No such file or directory
I guess that the non printable character "^M" at the end of the shebag is the reason
You can use vi to edit the file and remove the "^M" characters, or run dos2unix if it's available in your distro.
 
Old 02-18-2008, 02:56 AM   #3
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
At the start of your script you have

#! /bin/bash^M

get rid of the ^M ...

It looks like you created the script on a windows machine and/or with a windows text editor. Is this correct? Windows end-of-line is a carriage-return followed by a line-feed. In unix, it is just a line-feed. The ^M is a carriage return. The dos2unix utility will strip these for you.
 
Old 02-18-2008, 04:53 AM   #4
Stevie-B-242
LQ Newbie
 
Registered: Oct 2005
Posts: 9

Original Poster
Rep: Reputation: 0
...ahhh ...tripped-up by the old non-printed characters trick. %-)

I figured it was something along these lines but when I cat the scripts on my Linux host, the shebang line looked normal.

...anyway, < THANK YOU VERY MUCH > for your help with this!
...especially for the suggestion to use dos2unix!

I've never used this utility before but it was a life-saver in this case as it allowed me to clean-up a whole directory full of scripts in batch!

THANKS!
--Steve
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute python scripts GameMaker Programming 2 02-09-2006 04:46 AM
how to execute bash scripts from C????? :( cho Programming 2 06-19-2005 07:15 PM
cant execute any scripts Phonics3k Linux - Newbie 2 06-19-2002 08:00 AM
How to execute Linux scripts LenkaNguyen Linux - General 2 12-07-2001 03:12 PM
Can't execute *.cgi scripts. BrianG Linux - General 1 04-11-2001 03:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration