linux - Add data to Bash array over multiple scripts -


i need pass array data between 2 bash scripts.

i have controller configuration both scripts source (etc/config). in file have 3 arrays declared:

declare -a exesuccess declare -a exefailure declare -a exeunknown 

my master script calls various subscripts in parallel gather data , output array.

subscript:

exesuccess+=($output) #this works while script running 

master script:

for z in $(ls -l scripts)   sh $z &   wait done  echo "validating script output" echo ${exesuccess[@]} 

while scripts running, array populated needed, when exit, array emptied (i assuming destroyed).

does know how can keep array initialised on execution of master script?

thanks in advance!

the arrays not shared between different shells. each script run separate process, , build own private arrays, these lost when process exits. @upasana shukla's suggestion of running scripts source work (because runs them in main shell process, rather subshells/diferent processes), not allow run scripts in parallel. if want run them in parallel, simplest way have them output temporary files instead of arrays:

export tmpdir="$(mktemp -d "/tmp/$(basename "$0").xxxxxx")" || {     echo "error creating temporary directory" >&2     exit 1 }  z in scripts/*; # please don't parse ls    sh "$z" & done wait  echo "validating script output" cat "$tmpdir/exesuccess" rm -r "$tmpdir" 

and in individual scripts:

echo "$output" >>"$tmpdir/exesuccess" 

Comments