I am writing a shell script which is using a environment variable.
The environment variable has $1 set in the value. When I am using the env variable in the script, I need to use the $1 as the parameter passed from the script arguments.
Example:
export EXPORT_VAR="-DmyVariable=\$1"
In a shell script (myScript.sh), I have used the above env variable like below.
#!/bin/bash
exec $JAVA_HOME/bin/java $EXPORT_VAR com.myProject.myJob "$@"
I am running the script as follows:
./myScript.sh var1 var2
I want the following command to be executed
exec $JAVA_HOME/bin/java -DmyVariable=var1 com.myProject.myJob "var1 var2"
Please advise.
$1 is just an example. The environment variable can have $2....$N. The same variable should be assigned to -DmyVariable while execution