I use openjdk for my work, but sometimes I need oracle's JRE. I thought that I could use 'env' command for this, but can't figure out why it's not working.I have openjdk in /usr/lib/jvm/java-1.8.0-openjdk-amd64 and oracle's jdk in /usr/lib/jvm/jdk-8-oracle-x64when I'm running: env JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-x64 java -versioni get:java version 1.7.0_75OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-3)OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)but if i try: env JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-x64 env|grep JAVAI see:JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-x64I have 'feeling' that this is somehow related to process forking and inheritance. I know that i can simply use export name=variable command and etc. But would appreciate get explanation is it possible with 'env' command and how. Thank you! (I am using debian linux, unstable repo)
How to change JAVA_HOME temprorary with env command
linux;debian;environment variables;java
It is possible to do that using the env command, however you have to use a little work around and call sh, see the following code snippets:# env var=bla echo $var># env var=bla sh -c 'echo $var'> bla# echo $var>You can find more information using on info coreutils 'env invocation'Unfortunatelly I can't give you any further explanations why it only works using sh -c ''.It seems env has a rather non-intuitive behavior...# env PATH= echo $PATH> env: echo: No such file or directory# env PATH= /bin/echo $PATH> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin