1

when I try to command in command line it executes fine

$: /application/jre/bin/java -classpath /application/common/lib/apps.jar: ./updater.jar com.application.updatermain mobile

This executes perfectly fine and returns me the results whereas when I try putting this in a file called run.sh

If I create a run.sh as

/application/jre/bin/java -classpath /application/common/lib/apps.jar: ./updater.jar com.application.updatermain $@

and try to run it

./run.sh mobile

it acts weird

My java code:

if (args.length == 1) {
    if (args[0].equalsIgnoreCase("mobile") ) {
        updateDB = true;
    } else {
        System.out.println(" 1 :Usage: ./run.sh [mobile] "+ args[0]);
        return;
    }
}

It gives me the output

1 :Usage: ./run.sh [mobile] mobile

Am I missing anything here.

Thanks a lot

4
  • Don't put $@ in quotes. Commented Mar 2, 2014 at 13:55
  • Tried that didn't work :( Commented Mar 2, 2014 at 14:00
  • What do you gent when you print args (not only args[0])? Commented Mar 2, 2014 at 14:03
  • Why there is as space before "./updater.jar"? Should not it be part of the classpath? Commented Mar 2, 2014 at 14:06

2 Answers 2

1

it seems that some space add to argument. you must trim the arg[0] :

  if (args.length == 1) {
     if (args[0].trim().equalsIgnoreCase("mobile") ) {
        updateDB = true;
     }
  else {
        System.out.println(" 1 :Usage: ./run.sh [mobile] "+ args[0]);
        return;
     }
  }
Sign up to request clarification or add additional context in comments.

2 Comments

I am not getting any space, when I try to print it.
try this : System.out.println(" 1 :Usage: ./run.sh [mobile] #"+ args[0] + "#");
1

Remove the space before "./updater.jar"; the script "run.sh" should contain:

/application/jre/bin/java -classpath /application/common/lib/apps.jar:./updater.jar com.application.updatermain $@

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.