Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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).
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
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.
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.
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"
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.