I can't append to an array when I use
parallel
, no issues using a for loop.
### Parallel example:
append() { arr+=("$1"); }
export -f append
parallel -j 0 append ::: {1..4}
declare -p arr
### Output:
-bash: declare: arr: not found
### For loop:
for i in {1..4}; do arr+=("$i"); done
declare -p arr
### Output:
declare -a arr=(="1" ="2" ="3" ="4")
I thought the first example is a translation of the for loop in functional style, so what's going on?
Asked by Nickotine
(554 rep)
Jun 23, 2023, 06:37 PM
Last activity: Jun 25, 2023, 09:27 AM
Last activity: Jun 25, 2023, 09:27 AM