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):
. path/to/child/script.sh
Note:
.
exports all script variables to child script.
Practcal example
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:
#!/bin/bash
TEST=5
echo "a.sh: ${TEST}"
. ./b.sh
b.sh
file:
#!/bin/bash
echo "b.sh: ${TEST}"
2. add execution permissions for files
chmod a+x a.sh
chmod a+x b.sh
3. run a.sh
script
./a.sh
Output:
a.sh: 5
b.sh: 5