I posted a question about an hour ago that elicited no responses, I'm now trying something different and I'm gonna simplify my question by including less code, but if you want to look at the rest of the code I'm using please check my last question Parallel Processes in bash bitcoin monitor that records to sql leaking data? . I can't get these variables to successfully transfer to the subshell ./test. thank you for your help. The Array's IP Port Name and Address are defined outside of the for loop and I can put in an echo command to verify they are coming through.
for (( c=0; c<=$id-1; c++ ))
do
UnitIP=${IP[$c]}
UnitPort=${Port[$c]}
UnitName=${Name[$c]}
UnitActive=${Active[$c]}
sh -c ". ./test && echo \$UnitIP \$UnitPort \$UnitName \$UnitActive"
done
You can just export them in parent shell:
export UnitIP=${IP[$c]}
export UnitPort=${Port[$c]}
export UnitName=${Name[$c]}
export UnitActive=${Active[$c]}
./test.sh
All the variables will become available in test.sh
( you don't need to source it )