Page 1 of 1

Bad interpreter

Posted: Wed Apr 19, 2006 3:49 pm
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?

Posted: Wed Apr 19, 2006 6:19 pm
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

Posted: Wed Apr 19, 2006 7:21 pm
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.

Posted: Wed Apr 19, 2006 7:35 pm
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.

Posted: Wed Apr 19, 2006 8:08 pm
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?

Posted: Wed Apr 19, 2006 8:20 pm
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)

Posted: Wed Apr 19, 2006 8:29 pm
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.

Posted: Thu Apr 20, 2006 11:23 am
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?