Even better because more clean, use prefix notation (without set
) on the command you want to invoke:
CLASSPATH=/path/mysql-connector-java-ver-bin.jar:$CLASSPATH ANOTHER_VAR=bla ATHIRD_VAR=blu java -...
Now the java
process you invoke will be able to gather your temporary environment variable(s) CLASSPATH, ANOTHER_VAR
and ATHIRD_VAR
.
If you used export
, then the variables will also be set globally(?), at least on the script's environment. And, values of variables which already existed would be overwritten by the new values.
Advantages of prefix notation:
- previous values of a variable should stay unchanged, i.e. in the case the old values are being needed later on, then there would be no need to save the old values of the variables which already existed in order to restore them after the invocation
- no need to
unset
your temporary variables for cleanup purposes after the invocation