I did web search and have read several articles on using variables in bash, including wiki but could not understand why running in bash
FOO_VARIABLE=foo;./test does not result in test having
By default, when a process is created, it inherits a duplicate environment of its parent process, except for explicit changes made by the parent when it creates the child.
Also have read that: Exception of inheritance of environment variables
"except for explicit changes":
FOO_VARIABLE=foo ./test - results in
test script knowing
FOO_VARIABLE, but why in first way it does not?
echo $0 -bash cat ./test echo $MY_TEST MY_TEST=test$MY_TEST echo $MY_TEST MY_TEST=ret;./test test
Tested on CentOS 7 and Mac OS.
second way is to source (2nd script is called from 1st), then no
export needed - why my case is different?
AMEND to above: it was my rush and not very attentiveness to details: I missed
. (dot) in sourcing section, now I've read: https://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-vs-sourcing-it and that part is all clear.
https://askubuntu.com/questions/26318/environment-variable-vs-shell-variable-whats-the-difference Yes, mine is local, but why is it not passed via inheritance (fork call)?