
smooth |
I’m using bash.
Calling 2nd script from the 1st directly by name, like:
#!/bin/bash
#
# this 1st script script1.sh
export Var1=100; # OR declare -xi Var1; Var1=100;
…
…
echo $Var1
script2.sh
echo $Var1
…
EOF
————————
#!/bin/bash
#
# this 2nd script script2.sh
…
…
echo $Var1
Var1=$((Var1-1)); or any other arithmetic operation
echo $Var1
…
…
EOF

nmarco |
The problem is that the second script runs in it’s own subprocess. Therefore when the second script ends, the value for $Var1 will be the same as it was before calling the second script.
To overcome this, you can “source” the second script. In bash, this is accomplished with a “.” (period)
Therefore, instead of:
echo $Var1
script2.sh
echo $Var1
try this:
echo $Var1
. script2.sh
echo $Var1

smooth |
Just took a look to “man .”; will try. Thank you for tip, nmarco!