I am trying to make a shell script in which I want to pass the
-classpath "classpath-value" flag to the
javac command. I know I can use the
CLASSPATH environment variable to set the classpath, but I have a very specific need to do it this way.
What I want:
$ classpath_val="-classpath \"/opt/apache-tomcat-8.5.20/lib/servlet-api.jar\"" $ javac $classpath_val com/example/Test.java
However, when I executed the second command, it just executes as if the classpath_val were not supplied, so it doesn't use the
But if I echo the same command, I get:
$ echo javac $classpath_val com/example/Test.java javac -classpath "/opt/apache-tomcat-8.5.20/lib/servlet-api.jar" com/example/Test.java
Which is perfectly right.
Why is this happening? Is it that I can't supply arguments to a command from variable value?