I'm trying to create a bash script that will build a list of arguments before calling java, but I am having trouble getting a classpath argument with a wild card to work. The script so far:
#!/bin/bash
PROP_FILES=./props/default.properties
#EXTRA_PROP_FILES_HERE
ARGS="-cp \"lib/*\""
ARGS="$ARGS -Xmx10G"
ARGS="$ARGS -Duser.timezone=GMT"
ARGS="$ARGS -Danl.property.files=$PROP_FILES"
java $ARGS main.class.path.Main
The problem is with the ARGS="-cp \"lib/*\""
. I'm debugging the file with the command bash -x runscript.sh
.
If I escape the wildcard cp (like in the script above), the script fails with the output (note the extra single quotes):
java -cp '"lib/*"' ...
If I don't escape it, the *
expands to all of the jars in the lib directory and also fails
How do I modify the script so that it calls this?
java -cp "lib/*" ...
Note: I know I could just do java -cp "lib/*" $ARGS ..,
, but I'd really like to get this working.