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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -