I have a bazinga
property stored in an environment variable
export OPTS="-Dbazinga=\"foo bar\""
-bash-4.1$ echo $OPTS
-Dbazinga="foo bar"
Also, there is an example java program that just prints its value:
public class Main {
public static void main(String[] args) {
System.out.println(System.getProperty("bazinga", ""));
}
}
When I run the program without using the env variable everything works fine, meaning foo bar
is printed:
-bash-4.1$ java -Dbazinga="foo bar" Main
foo bar
However, I am unable to run the program using the variable because qoutation marks get in the way:
-bash-4.1$ java $OPTS Main
Error: Could not find or load main class bar"
-bash-4.1$ java "$OPTS" Main
"foo bar"
How can I run the program using the env variable with correct quotation marks handling?