Skip to content
Advertisement

Setup or env variable lost after running bash files

Please excuse me if there is an error in the sample code.

There are two files testA.sh and testB.sh.

testA.sh

JavaScript

testB.sh

JavaScript

deepak[18:33] $ ./testA.sh
test b
hello

deepak[18:33] $ echo $a

deepak[18:33] $

If we run any setup in the testB.sh then how can we use that setup or env variable in the main console (for example echo $a)

Advertisement

Answer

testA.sh runs in a subshell, and it’s environment evaporates with it when it ends.

if you source testA.sh it will keep the value.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement