What's the difference between:
I understand that they both define environment variables, but I don't fully understand the difference.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
export propagates the variable to subprocesses.
For example, if you did
then a subprocess that checked for FOO wouldn't find the variable whereas
would allow the subprocess to find it.
FOO has already been defined as an environment variable, then
FOO=bar will modify the value of that environment variable.
FOO=one # Not an environment variable export FOO # Now FOO is an environment variable FOO=two # Update the environment variable, so sub processes will see $FOO = "two"
Older shells didn't support the
export FOO=bar syntax; you had to write
FOO=bar; export FOO.
Also, if you want to have the variable available to the calling shell without using export you can do this:
File a.ksh is -
On the prompt, run this is
> . a.ksh
This will run the commands within the same shell and $FOO will be available.
Will make $FOO available only within a.ksh, after the call to a.ksh it would not exist.