EN
Bash - pass variables from one script to second one
10 points
In this short article we would like to show how in Bash pass variables from one script to second one.
Quick solution (call child script following way):
xxxxxxxxxx
1
. path/to/child/script.sh
Note:
.
exports all script variables to child script.
To see how it works we can use below example that needs to create in same directory 2 sh files.
Do following steps:
1. create scripts
a.sh
file:
xxxxxxxxxx
1
2
3
TEST=5
4
5
echo "a.sh: ${TEST}"
6
7
. ./b.sh
b.sh
file:
xxxxxxxxxx
1
2
3
echo "b.sh: ${TEST}"
2. add execution permissions for files
xxxxxxxxxx
1
chmod a+x a.sh
2
chmod a+x b.sh
3. run a.sh
script
xxxxxxxxxx
1
./a.sh
Output:
xxxxxxxxxx
1
a.sh: 5
2
b.sh: 5