LinuxQuestions.org
Review your favorite Linux distribution.
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-29-2016, 08:52 AM   #1
iFunction
Member
 
Registered: Nov 2015
Posts: 206

Rep: Reputation: Disabled
bin/bash: bad interpreter


Hi there,

can anyone tell me why I am getting this error from this script, I wrote it on this linux computer, so it is not a Windows/Mac to linux problem:

Code:
#!/bin/bash

myfilename=$0
echo $myfilename
I have changed the permissions using chmod for all to be able to execute, and I am calling it with:
Code:
pi@mybox: ~/bash_scripts $ ./testfile
In case it is needed:
Code:
which bash
returns:
Code:
/bin/bash
any help on this would be much appreciated
 
Old 02-29-2016, 09:09 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,527

Rep: Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439Reputation: 2439
I think you mistyped something. Please post the content of the file, not only lines-letters. Please post the full response, not only parts.
Put set -xv at the beginning of the script to see what's happening.
 
Old 02-29-2016, 09:37 AM   #3
iFunction
Member
 
Registered: Nov 2015
Posts: 206

Original Poster
Rep: Reputation: Disabled
I don't understand, this is my complete script. What is the content of the file?

in emacs, I typed (without the codeblocks)
#!/bin/bash

myfilename=$0
echo $myfilename


Then I did [ctrl]+x [ctrl]+s to save the file.
What is the contents of the file that you are requesting? I am trying to follow a tutorial about arguments and trying to learn about $0, $1 etc. Mu assumption is that $0 refers to the filename that was used to call the script which in this case was "testfile.sh", well actually, it was "tes" and then the tab key to autocomplete to make sure I have the correct file name.
 
Old 02-29-2016, 09:44 AM   #4
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.1 MATE
Posts: 1,941

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
I'll leave pan64 to clarify what he is asking for, but can you please cut and paste (not retype) the actual error message that you are receiving (the whole line and any lines around it that may refer to the error).
 
Old 02-29-2016, 09:46 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
I cannot see anything in particular, but do note that your last post refers to "testfile.sh", but in your running example it is "./testfile", ie. without the .sh
 
Old 02-29-2016, 09:49 AM   #6
iFunction
Member
 
Registered: Nov 2015
Posts: 206

Original Poster
Rep: Reputation: Disabled
Ok, I can't figure this one out, so I wrote another script to see if that worked and it works fine, it's just a shame that there was no way of troubleshooting this problem so I can learn from it.
 
Old 02-29-2016, 09:53 AM   #7
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.1 MATE
Posts: 1,941

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Quote:
Originally Posted by iFunction View Post
Ok, I can't figure this one out, so I wrote another script to see if that worked and it works fine, it's just a shame that there was no way of troubleshooting this problem so I can learn from it.
There is always a way to troubleshoot problems.

You were asked to provide specific info to allow us to help you to do that. If you still want to determine what caused the problem, let's continue with that. On the other hand, if you want to just put it down to "c'est la vie" then that's fine.
 
Old 02-29-2016, 11:39 AM   #8
iFunction
Member
 
Registered: Nov 2015
Posts: 206

Original Poster
Rep: Reputation: Disabled
Unfortunately, I deleted the file, I had posted all there was, it was literally just those three lines, and the error message was in the terminal was just that one line:
Code:
bash: ./testfile.sh: bad interpreter: No such file or directory
So when more was asked for, I didn't have anything else to post up.

Ultimately, this is a Raspberry Pi I am currently working with, and although I have emacs running on here, there are some quirks in it can't just be opened up from the start menu or an icon and used, as it only opens in read only. So this has to be opened from Terminal prefixed with Sudo. There are other quirks also, for some reason it only reads the .emacs file if run from the start menu, but as mentioned earlier, it only opens as read only mode. I am suspecting that it is on of these quirks that caused the problem in the first place.

TBPH, there are too many unknowns to follow this one through now at this point, but my initial reaction is that it was not my script causing the problem, but was something that had been sent to the shell from emacs that did not agree with it, hence the "Bad Interpreter"

Kind regards

iFunc
 
Old 02-29-2016, 11:55 AM   #9
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.1 MATE
Posts: 1,941

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Quote:
Originally Posted by iFunction View Post
Code:
bash: ./testfile.sh: bad interpreter: No such file or directory
That's unusual, because this error message is normally of the form:

bash: <bash script path>: <interpreter declaration>: bad interpreter: No such file or directory

which would indicate that your script was being interpreted as having no characters at all after the initial #! since there was nothing in the error message in the <interpreter declaration> field.

For info, that was why a cut and paste of both the original script and the output was useful - to see exactly how the first line in the script was formed, and likewise for the error.

It is most likely that one or more non-printing characters had wheedled their way in there, the sort of thing that can happen with cut and paste from web sites or other systems, or perhaps a slip of the fingers in a text editor.

Last edited by hydrurga; 02-29-2016 at 11:56 AM.
 
1 members found this post helpful.
Old 02-29-2016, 04:20 PM   #10
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,685
Blog Entries: 10

Rep: Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080
Run in debug-mode (regardless of attributes) in Terminal >
Code:
bash -vx ./testfile.sh
Observe and Report.
 
Old 02-29-2016, 04:49 PM   #11
iFunction
Member
 
Registered: Nov 2015
Posts: 206

Original Poster
Rep: Reputation: Disabled
Yes, I think you are quite correct, sorry for not following this one through, I will pay a little more attention next time. As I said, I have got it working now, by just writing it again, it's a missed opportunity I'm afraid.

Thanks very much for your patience.
 
Old 02-29-2016, 05:23 PM   #12
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 3,110

Rep: Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543
I got it to work, without error

code:

Code:
#!/bin/bash

myfilename=$0
echo $myfilename
saved as testfile
Code:
chmod +x testfile
output from executing in the directory the script is off of the command line:
Code:
# ./testfile
./testfile
#
you do not actually need the .sh at the end of a script. that has nothing to do with getting it to work.
All that is is a naming convention to allow anyone that sees that file in a directory to just know it is a script just by looking at it. nbd

it's contents and permissions and how it is executed are all that matters to get it to work.

and yes I'm in root. Because I can roll like that

Last edited by BW-userx; 02-29-2016 at 05:32 PM.
 
Old 02-29-2016, 05:36 PM   #13
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 3,110

Rep: Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543Reputation: 543
Quote:
Originally Posted by iFunction View Post
Yes, I think you are quite correct, sorry for not following this one through, I will pay a little more attention next time. As I said, I have got it working now, by just writing it again, it's a missed opportunity I'm afraid.

Thanks very much for your patience.
Code:
pi@mybox: ~/bash_scripts $ ./testfile
if you look closely you'll see what I do. you have a space between the $ (and) ./testfile
that was your error
cheers
 
  


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
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or director irlogo Red Hat 5 03-12-2012 05:38 AM
/bin/bash^M: bad interpreter: no such file or directory stevesk Slackware 18 03-07-2012 12:58 PM
-bash: ./configure: /bin/sh: bad interpreter: Permission denied cwwilson721 Slackware 28 12-25-2010 05:11 AM
/bin/bash: bad interpreter: Permission denied cap_ahab Linux - General 4 01-17-2006 09:11 AM


All times are GMT -5. The time now is 07:18 PM.

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