Set variables in parallel in bash -
here's example program:
#!/bin/bash x in {1..5} output[$x]=$(echo $x) & done wait x in {1..5} echo ${output[$x]} done
i expect run , print out values assigned each member of output
array, prints nothing. removing &
correctly assigns variables. must use different syntax achieve in parallel?
this
output[$x]=$(echo $x) &
puts whole assignment in background task (sub-process) , that's why you're not seeing result, since it's not propogated parent process.
you can use wait wait subprocesses, returning results (other status codes) going difficult. perhaps can write intermediate results file, , collect results after processes have finished ? (not nice, appreciate)
Comments
Post a Comment