I've noticed something odd in bash. Let's suppose I have a file toto containing the following :
#!/bin/bash
export foo=2
if I run source toto; echo foo=$foo
, I get as expected
foo=2
However, if I run bash -c "source toto; echo foo=$foo"
, I get
foo=
Same thing if I run
bash << EOF
source toto
echo foo=$foo
EOF
Still, If I create a file test.sh containing:
#!/bin/bash
echo foo=$foo
And then I run bash -c "source toto; ./test.sh"
then I finally get the expected
foo=2
Does someone understand these results? Thanks!