LinuxQuestions.org
Review your favorite Linux distribution.
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 08-25-2005, 04:04 AM   #1
hanasi
Member
 
Registered: Jul 2005
Distribution: SUSE Linux v9.2
Posts: 85

Rep: Reputation: 15
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?
 
Old 08-25-2005, 04:06 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If the directory isn't in your path and assuming the script is call run, you need to type "./run" (without the quotes).
 
Old 08-25-2005, 05:20 AM   #3
hanasi
Member
 
Registered: Jul 2005
Distribution: SUSE Linux v9.2
Posts: 85

Original Poster
Rep: Reputation: 15
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!!
 
Old 08-25-2005, 08:40 AM   #4
hanasi
Member
 
Registered: Jul 2005
Distribution: SUSE Linux v9.2
Posts: 85

Original Poster
Rep: Reputation: 15
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?
 
Old 08-25-2005, 09:33 AM   #5
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
try "sh run".
 
Old 08-25-2005, 01:40 PM   #6
hanasi
Member
 
Registered: Jul 2005
Distribution: SUSE Linux v9.2
Posts: 85

Original Poster
Rep: Reputation: 15
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.
 
Old 08-25-2005, 01:42 PM   #7
mugstar
Member
 
Registered: Jun 2004
Location: Scotland
Distribution: Anything that'll install...
Posts: 305

Rep: Reputation: 30
Change the first line to #!/bin/bash and you might have more luck.
 
Old 08-25-2005, 02:21 PM   #8
hanasi
Member
 
Registered: Jul 2005
Distribution: SUSE Linux v9.2
Posts: 85

Original Poster
Rep: Reputation: 15
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".
 
Old 08-25-2005, 02:28 PM   #9
mugstar
Member
 
Registered: Jun 2004
Location: Scotland
Distribution: Anything that'll install...
Posts: 305

Rep: Reputation: 30
<writes quick hello world to test...>

You're not wrong - never knew that one!
 
Old 08-25-2005, 08:04 PM   #10
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
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?
 
Old 08-25-2005, 09:22 PM   #11
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
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?
 
Old 08-25-2005, 09:48 PM   #12
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
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).
 
Old 08-26-2005, 01:20 AM   #13
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
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?
 
Old 08-26-2005, 07:55 AM   #14
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Right ... that's true. The one time I ran into that, it wound up being a permission problem, but no idea in this case.
 
Old 08-27-2005, 03:14 PM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


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
can i make a script or program make a phone call? nephish Linux - Software 2 08-15-2005 09:02 PM
How do I make a script run at boot? ToothlessRebel Linux - Newbie 9 04-27-2005 01:46 AM
make hotplug run a script on detect bobbens Linux - Software 5 01-13-2005 11:42 AM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM

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

All times are GMT -5. The time now is 02:51 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