1

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.

3
  • 3
    Why the eval? Why not just make test-all-basics directly? Commented Apr 20, 2014 at 2:26
  • @kojiro Good point. Originally, names of tests were passed by a file, but I understand now, that eval is redundant in this case. Is that connected with a question though? Commented Apr 20, 2014 at 3:51
  • If you mark a name for export it will remain marked in all child processes unless a child process unmarks it. A name marked for export will retain the value set in a parent process through its children unless a child process changes it. So if your name doesn't have the value you expect, or is unset, look for what's unexporting or changing it. Commented Apr 20, 2014 at 12:39

2 Answers 2

1
#!/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"
...
Sign up to request clarification or add additional context in comments.

Comments

0

Inside script one use,

export CADEPTH=....
let CADEPTH=...
echo $CADEPTH

and inside script two, do:

source script1

and then,

echo $CADEPTH

2 Comments

Thing is that script 1 calls script 2. So if I source in source script1 in script2 it looks like I'm getting an infinite loop
All you need is to export the variable in script 1 -- no other changes required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.