Bad interpreter

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Bad interpreter

Post by a94060 »

Hi guys,

When i run the command:

Code: Select all

./ip.sh
to set my iptables up, i get this

This is how my screen looks after i run the command and do a dir listing.

Code: Select all

ftp:/home/avi# ./ip.sh
: bad interpreter: No such file or directory
ftp:/home/avi# dir
ip.sh  public_html
ftp:/home/avi#
could someone tell me why im getting the no such file error?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Look at the shebang line.

The shebang is the first line in your script that you're trying to run and looks something like:

#!/bin/sh

Make sure that path you see actually exists and adjust it accordingly if not.

You could manually execute it using sh:

sh ip.sh
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Most commonly associated with 'sausaged' line endings i.e. the script has been writen/modified using an editor which saves/converts the file's line endings to something other than 'LF'.

Of course as suggested above, could just be you have specified a non-existant interpreter or the shebang line is missing.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

redmonkey wrote:Most commonly associated with 'sausaged' line endings i.e. the script has been writen/modified using an editor which saves/converts the file's line endings to something other than 'LF'.

Of course as suggested above, could just be you have specified a non-existant interpreter or the shebang line is missing.

i pretty sure that the /bin/ stuff is there because i was able to originally run the script. What do you mean by the LF? i acquired this script from the forums and i jus copied and pasted it into putty and saved it as an sh file.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Putty isn't an editor. Have you changed/edited the file since? if so which editor did you use?

LF (or perhaps better understood as '\n') is the native line ending for Unix files, different operating systems use different line endings and in many cases the editors used default to the native line endings for which ever OS they are running on. Windows uses CR and LF (also noted as '\r\n') Macs use CR ('\r'). If you've pasted the script into an editor running on another OS, there is a possibility that the editor has added/changed the line endings to the OS's native line endings which can cause the 'Bad Interpreter' error.

The error message is normally more than just 'Bad Interpreter', was there any more to the message in your case?
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

thats all i saw on my screen. i know that putty is not an editor. while i ssh'ed in,i did nano ip.sh and then copied the entire text by copy and paste.is there any way i can fix this? (this is a script from this forum)
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

You first need to determine what the exact cause of the problem is before you can fix it. It may or may not be an issue with line endings (it probably isn't as you are using nano).

Why not write (from scratch) a simple script and try running it through the same interpreter.

If it is a line ending problem then there are a few file conversion utils available, try your favourite search engine for 'dos2linux' (or similar) I think that's the right name.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,i will try to use a converter. I formatted the text by copying pasting into wordpad then recopying and pasting into Putty.

EDIT-Can i open the file up in nano and then resave it? will it convert the endings?
Post Reply