开发者

What does $1 mean in JAVA?

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开发者_Go百科

 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??


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);
    }
}


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


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/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜