#!/bin/bash
# SCRIPT ONE
CAPDEPTH=1
...
while [ $CAPDEPTH -lt 11 ]; do
echo "cap depth - $CAPDEPTH"
export CAPDEPTH # Makes it so that any child process inherits the variable CAPDEPTH and anything it contains.
make test-all-basics
let CAPDEPTH++ # Increments CAPDEPTH by +1
done
# SCRIPT TWO
...
R_binary="${R_HOME}/bin/exec${R_ARCH}/R"
capture_arg="--tracedir $CAPDEPTH"
...
Propagate values in shell script
-
06-07-2023 - |
Question
I have a simple script that uses CAPDEPTH like a count variable and calls some tests for each value.
#!/bin/bash
# SCRIPT ONE
CAPDEPTH=1
...
while [ $CAPDEPTH -lt 11 ];
do
echo "cap depth - $CAPDEPTH"
make test-all-basics
let CAPDEPTH=CAPDEPTH+1
done
And in line
eval "make test-all-basics"
It will do multiple calls to another shell script which I also want to make dependent on value of CAPDEPTH. Here are couple of lines from that script.
# SCRIPT TWO
...
R_binary="${R_HOME}/bin/exec${R_ARCH}/R"
capture_arg="--tracedir $(CAPDEPTH)"
...
My question is how to get the value of CAPDETH propagated from SCRIPT ONE to SCRIPT TWO. Is that even possible? I've tried export of the variable CAPDEPTH in both scripts, but does not seems to work.
Solution
OTHER TIPS
Inside script one use,
export CADEPTH=....
let CADEPTH=...
echo $CADEPTH
and inside script two, do:
source script1
and then,
echo $CADEPTH
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow