Two types of Variables

Published: Monday, Oct 26, 2020 Last modified: Monday, Jul 15, 2024

[hendry@t14s e]$ cat envfile
[hendry@t14s e]$ source ./envfile
[hendry@t14s e]$ echo $FOO
[hendry@t14s e]$ printenv | grep FOO
[hendry@t14s e]$

Why isn’t FOO in the environment? Because it was not exported!

Bash has two types of variables. Shell Variables (foo=bar) live in the running shell and are copied to subshells. Environment Variables (export foo=bar) are special variables that live in a PROCESS and are copied to each new process it creates. They are used the same way but CREATED differently. Env vars are NOT system-wide or “shared” in any way.