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 am installing a Java program which I have used before on other OSes. It comes with a sh script to start it, and the script is properly identified in the first line as an sh script. The file is quite short, and I have reviewed its contents for accuracy; it seems to be in order.
I assume that the file has to be made executable, and I have done this. For the time being, there are three "x"s in the permissions.
From the command line, in the directory in which the script resides, I try to run the script by typing its name. This gets me an instant retort as follows:
*****
bash: run: command not found
*****
So it is clear that I have misunderstood something somewhere, and done, or omitted to do, something, though I can't see where there was much room for error.
Originally posted by Nylex If the directory isn't in your path and assuming the script is call run, you need to type "./run" (without the quotes).
Your suggestion did make a difference, although one not as great as I had hoped. When I now run the script by typing "./run" (from the directory containing "run") the reaction is:
*****
: bad interpreter: no such file or directory
*****
Since I can see that the script "run" is right there in front of me, something must indeed be bad. How to fix it?
This worked, thank you. It has also left me very confused. Here is the script in its entirety:
*****
#!/bin/sh
#
cd /home/stan/bin/genj
java -classpath ./lib/genj.jar genj.app.App
*****
I have found in the meantime some literature on shell scripts. It seems to be telling me that, because of the irst line, I should be able to run it simply by typing its name, as I tried initially (and unsuccessfully. It isn't clear to me why that failed. But there are even more serious confusions which are not touched on by the documentation I have found.
Firstly, the cd line doesn't work at all. It gets an error message saying "no such file or directory". There IS such a directory, and I am running the script from it. Since this is an absolute directory specification, it should leave me just where I am, and make no complaint. But it doesn't matter what directory I specify, I get the same error message.
The jave line gets an error message from the JVM, indicating that it couldn't find genj.app.App.
This line is correct, although I may have abused some Linux rule in writing it exactly so. The lib directory is, as it says, one directory down from the directory I am in (and which the cd line was meant to bring me to if I had started from some other directory). The entry point (genj.app.App) is correct. These two logether work in other OSes, given only the obvious directory changes from system to system, and turning "/" into "\".
While problem of the cd line is script-related, and presumably belongs in this forum, the problem of the java line would probably be better put somewhere else. But I see no forum here or elsewhere where the connection between Linux and Java are addressed. If someone would like to direct me to one, I would be overjoyed and grateful.
I should be able to run it simply by typing its name
I have no idea why, but some scripts (seems to happen moreso with those pointing to /bin/sh) seem to work only if you run "sh <scriptname>"
Quote:
java -classpath ./lib/genj.jar genj.app.App
isn't the entry point for a jar file contained in it's metafile? you should be able to run a jar with "java -jar /path/to/file.jar" (assuming it's a lone jar file, not dependant on other files in the directory, in which case you will need to be in the directory or set the -classpath switch).
Quote:
"sh" is an alias for "bash"
wow, I was always under the impression that sh was a totally different enterpreter than bash. what's up with that?
If the shell script isn't executable and . isn't in your $PATH, the shell won't run it automatically.
but it was executable and he typed "./run", so it should have worked, but for some reason it says it couldn't find the enterpreter, even though the path in the shebang is correct. I've encountered this a few times, too. Anyone know why that is?
Several possibilities... one or more of the libs that the shell
is linked against have the wrong permissions.
The partition he's trying to run it from is mounted noexec
(I occasionally do that with home ;} for machines that others
have accounts on when I have to suspect that they may be
installing unwanted software) ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.