LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can't make a script run (https://www.linuxquestions.org/questions/linux-newbie-8/cant-make-a-script-run-356772/)

hanasi 08-25-2005 04:04 AM

Can't make a script run
 
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.

What must I do to run this script?

Nylex 08-25-2005 04:06 AM

If the directory isn't in your path and assuming the script is call run, you need to type "./run" (without the quotes).

hanasi 08-25-2005 05:20 AM

Quote:

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).
Aha!!

Nonintuitive, but reasonable after you know it. I never would have tumpled to it by myself, because it looks reduncant.

I'll change the name of the script to something unique, and add its location to the path, which I would have had to do in the end anyway.

Many thanks!!

hanasi 08-25-2005 08:40 AM

Quote:

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?

Ynot Irucrem 08-25-2005 09:33 AM

try "sh run".

hanasi 08-25-2005 01:40 PM

Quote:

Originally posted by Ynot Irucrem
try "sh run".
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.

mugstar 08-25-2005 01:42 PM

Change the first line to #!/bin/bash and you might have more luck.

hanasi 08-25-2005 02:21 PM

Quote:

Originally posted by mugstar
Change the first line to #!/bin/bash and you might have more luck.

Not so. "sh" is an alias for "bash".

mugstar 08-25-2005 02:28 PM

<writes quick hello world to test...>

You're not wrong - never knew that one!

Ynot Irucrem 08-25-2005 08:04 PM

Quote:

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?

jrdioko 08-25-2005 09:22 PM

Quote:

Originally posted by Ynot Irucrem
wow, I was always under the impression that sh was a totally different enterpreter than bash. what's up with that?
Me too, what happened to the original sh?

btmiller 08-25-2005 09:48 PM

If the shell script isn't executable and . isn't in your $PATH, the shell won't run it automatically.

As bash is just a very souped up sh, I guess distro maintainers didn't see a point of including them both (the BSDs do).

Ynot Irucrem 08-26-2005 01:20 AM

Quote:

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?

btmiller 08-26-2005 07:55 AM

Right ... that's true. The one time I ran into that, it wound up being a permission problem, but no idea in this case.

Tinkster 08-27-2005 03:14 PM

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) ...


Cheers,
Tink


All times are GMT -5. The time now is 11:48 AM.