Are simple command variable assignments accessible in nested scripts? e.g., does `child.sh` have "FOO=BAR" when running "FOO=BAR ./parent.sh"?
-4
votes
1
answer
74
views
Although this is easy to try and see, I was looking for the answer on StackOverflow and couldn't find it. That's why I'm asking and answering my question.
I recommend reading this first. The answer is hinted at, but not directly stated.
---
I have these two shell scripts:
$ cat parent.sh
echo $(basename "$0")
echo "$FOO"
./child.sh
$ cat child.sh
echo $(basename "$0")
echo "$FOO"
What will be printed if I run this command: FOO=BAR ./parent.sh
Asked by Daniel Kaplan
(1070 rep)
May 17, 2025, 09:33 PM
Last activity: May 17, 2025, 10:46 PM
Last activity: May 17, 2025, 10:46 PM