tags:

views:

136

answers:

3

Here is a shell script:

echo Starting Jarvis Program D.
ALICE_HOME=.
SERVLET_LIB=lib/servlet.jar
ALICE_LIB=lib/aliceserver.jar
JS_LIB=lib/js.jar

# Set SQL_LIB to the location of your database driver.
SQL_LIB=lib/mysql_comp.jar

# These are for Jetty; you will want to change these if you are using a different http server.
 HTTP_SERVER_LIBS=lib/org.mortbay.jetty.jar

 PROGRAMD_CLASSPATH=$SERVLET_LIB:$ALICE_LIB:$JS_LIB:$SQL_LIB:$HTTP_SERVER_LIBS
 java -classpath $PROGRAMD_CLASSPATH -Xms64m -Xmx128m org.alicebot.server.net.AliceServer $1

On the last line: what does the $1 mean??

+8  A: 

It's not Java, it's the shell scripting language. $1 is the first argument supplied on the command line. It tells the script to pass the first command line argument that you gave along to java.exe. It, in turn, with be the first argument in your call to main().

If your main looked like this, and the value you supplied was "foo", the output would be "foo":

public static void main(String [] args)
{
    for (String arg : args)
    {
        System.out.println(arg);
    }
}
duffymo
What would the first command line argument be then?
Elijah W.
if the name of the script is jarvis.sh, and you start it in a command shell by typing "jarvis.sh foo", then the first argument is "foo".
duffymo
Look at my comment to duffymo. I'm lost....
Elijah W.
What is the problem? You're asking a new question: "What does it mean to pass an argument into the shell I posted?" Could you please edit your original question to provide more context and clarity as to the exact problem?
duffymo
+2  A: 

$1 in shell scriping means "argument number 1 passed to this shell script".

For instance, if you have a shell script called "foo.sh", with the following contents:

#!/bin/sh
echo "$1"

and you called it with ./foo.sh hello world, then hello is the first argument passed to the script, and the echo "hello" command will be executed and print hello onto the screen.

Frxstrem
Would would $1 be in my shell script?
Elijah W.
If you don't pass a command line argument, then it's a blank string.
duffymo
Well, I'm running it through NSTask and it seems like it's freezing my code unless I put an argument. I put "H". It errored: "Could not find "H"!" I'm confused...
Elijah W.
Looks like you have to have Jetty and MySQL running. Do you?
duffymo
"Seems like" - how do you know?
duffymo
Yes that is correct.
Elijah W.
A: 

Just for the curious, here's the entire code environment for the shell script called server.sh:

http://sourceforge.net/projects/charliebot/

Some more information can be found here:

# http://www.alicebot.org/resources/programd/readme.html
# http://www.noendpress.com/caleb/ALICE101_MacOSX/
frank
Yep! This is what I'm trying to run.
Elijah W.