LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 07:52 AM   #1
iFunction
Member
 
Registered: Nov 2015
Posts: 248

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, 08:09 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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, 08:37 AM   #3
iFunction
Member
 
Registered: Nov 2015
Posts: 248

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, 08:44 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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, 08:46 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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, 08:49 AM   #6
iFunction
Member
 
Registered: Nov 2015
Posts: 248

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, 08:53 AM   #7
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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, 10:39 AM   #8
iFunction
Member
 
Registered: Nov 2015
Posts: 248

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, 10:55 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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 10:56 AM.
 
1 members found this post helpful.
Old 02-29-2016, 03:20 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

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

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, 04:23 PM   #12
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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 04:32 PM.
 
Old 02-29-2016, 04:36 PM   #13
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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



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 04:38 AM
/bin/bash^M: bad interpreter: no such file or directory stevesk Slackware 18 03-07-2012 11:58 AM
-bash: ./configure: /bin/sh: bad interpreter: Permission denied cwwilson721 Slackware 28 12-25-2010 04:11 AM
/bin/bash: bad interpreter: Permission denied cap_ahab Linux - General 4 01-17-2006 08:11 AM

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

All times are GMT -5. The time now is 11:56 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
Open Source Consulting | Domain Registration