1

I have a script which takes command line arguments and after some processing, it sends these arguments to the java application.

Some of these arguments can be quoted and I want to send those arguments as it is (in the quote). I am using following script:

$ARGS=""
for a in $@; do
    ARGS = ${ARGS} ${a};
done
exec $JAR $ARGS

where $JAR contains command to run the jar.
But, if I run the script with following options:

script x y "a b" 

The script treats the three parameters as x, y and a b.
And I want it to consider these parameters as: x, y and "a b".

sachinpkale
  • 989
  • 3
  • 14
  • 35

1 Answers1

2

Use an array for the arguments.

$ARGS=()
for a in "$@"; do
    ARGS+=("${a}")
done
exec "$JAR" "${ARGS[@]}"
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358