Difference Between `VAR=…` and `export VAR=…` in Bash


What is the difference in doing

$ MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=384m"

to doing

$ export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=384m"

and is there any side-effect of doing either in an SSH connection?

Best Answer

The 1st one sets the value to the variable. For instance you can do


and have it return the value but if you would issue that outside your shell you will have an empty string returned.

In comes export.

Export is an instruction to the shell. It tells the shell to make this environment variable available to other programs. Without the export, they are only available within the shell itself.

If you want the variable to be permanently available ssh reads ~/.ssh/environment,ssh2 reads /etc/environment and ~/.ssh2/environment, and adds lines of the format VARNAME=value to the environment. From the ssh man page.