There are 2 different types of variables (actually more than that, but in this context just 2), private and exported.
Private variables are variables which can be used in the shell (or script) but not by programs launched by the shell (or script).
You can get a list of all variables including exported ones by using
set. In bash all 3 do the same thing.
Exported variables can be used by both the shell or programs launched by it.
You can get a list of exported variables by using
One key thing to note is when doing things such as this:
$FOO is a private/non-exported variable. The shell is actually expanding
bar before it passes it to
echo is actually being called as
You can export variables by doing
export FOO, or
Additionally you can export a variable for just a single call to a program by adding the variable at the beginning of the command. For example
cmd1 will have access to
cmd2 will not.