I have implemented a chat server client. I have written the following shell script to dynamically take in the server port number: server.sh
javac -classpath . com/chat/ChatConstants.java
javac -classpath . com/chat/ChatServer.java
echo Enter server port number
read $1
java com.chat.ChatServer $1
This is the java main method I am trying to pass the argument to :
public static void main(String args[]) {
// The default port number.
int portNumber = 8888;
if (args.length < 1) {
System.out.println("Chat server is up on " + portNumber);
} else {
portNumber = Integer.valueOf(args[0]).intValue();
System.out.println("Chat server is up on " + portNumber);
}
}
However, the port number printed is always the default port ie 8888. When I run the java program as follows
java com.chat.ChatServer 2727
The cmd line args are taken properly and server port is set to 2727.
I seem to be doing something wrong in the shell script. I even tried passing the arguments with quotes as follows:
java com.chat.ChatServer "$1"
The command prompt closes promptly.
Please help