Trying to stop using files output to store data from a parallel for loop. I want to run the output of array through paralleled commands using input from the array and store the results when its completed in the array in the correct order.
Logic-ish code:
for i in `do some stuff`
do
bunch of stuff based on variables in the loop run in parallel but output saved in the right order
done
Broken Code:
#!/usr/bin/bash
IFS=$'\n'
for i in $(seq 1 1 10)
do
export MYBROKENARRAY+=(`echo POTATO;wait`) &
done
sleep 1
echo MYBROKENARRAY IS "${MYBROKENARRAY[@]}"
if I keep the & I get my parallel but the output is not stored in the array as expected
expedited output is:
MYBROKENARRAY IS POTATO POTATO POTATO POTATO POTATO POTATO POTATO POTATO POTATO POTATO
This is how I to it today with ugly file output ... :(
#!/usr/bin/bash
IFS=$'\n'
for i in $(seq 1 1 10)
do
echo POTATO > out_${i}.txt &
done
cat out_*.txt
for i in `do some stuff`is almost certainly wrong; see Bash FAQ 001.