What is the difference between `VAR=...` and `export VAR=...`?

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?


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

echo $MAVEN_OPTS

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 executed from the same shell. 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.


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

Sets a shell variable named MAVEN_OPTS. It is probably followed by an export MAVEN_OPTS command to make this variable available as environment variable to child programs, or a shell command that uses it like java $MAVEN_OPTS ...

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

Sets a environment variable named MAVEN_OPTS. This environment variable is also available to child programs.

There are no side-effects except for that some java memory limits are adjusted for maven (a build system iirc).