2

I have a simple bash script which runs my java program. Here is it:

run.sh

#!/bin/sh
java -jar target/my-jar-arch.jar

I want to pass arguments to this script, which must pass them to java program:

bash run.sh myArg -key 100

When I try to execute this line my app doesn't get any parameters. How can I fix it?

chepner
  • 497,756
  • 71
  • 530
  • 681
Aaron
  • 1,294
  • 4
  • 14
  • 27

1 Answers1

6

Change your invocation line to:

java -jar target/my-jar-arch.jar "$@"
fge
  • 119,121
  • 33
  • 254
  • 329
  • Oh maybe you know how to make my script executable? If I run it `run myArg -p 100` I get `-bash: run: command not found`. Seams the problem is in my env. – Aaron Dec 07 '14 at 16:07
  • It should be `./run.sh`. Unix systems won't automagically "append extensions" or whatever; in fact they don't have the notion of an extension at all. – fge Dec 07 '14 at 16:12
  • The problem isn't in extension. It is in my .bash_profile I think. – Aaron Dec 07 '14 at 16:12
  • is there any possibility to pass few bash variables in to the java -jar command? Eg:- java -jar org.sample.jar $HOST $PORT assume I already have HOST and PORT defined within my bash script. – udarakr Apr 02 '16 at 22:16