What's the difference between:
I understand that they both define environment variables, but I don't fully understand the difference.
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.
Older shells didn't support the
Actually, if you don't use "export", you're not defining an environment variable, but just a shell variable.
Shell variables are only available to the shell process; environment variables are available to any subsequent process, not just shells.
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
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.
In addition to what has already been answered, both of these statement do not necessarily define (i.e. create vs set) an environment variable as "a" might already exist as a shell or environment variable.
In the latter case, both statements are strictly equivalent.