Problem: I cannot update the array in a while . Illustration (not a real problem):
declare -A wordcounts wordcounts["sentinel"]=1000 ls *.txt | while read f; do
This does not work because the loop after the channel runs in a subshell. All changes that the loop makes to the wordcounts variable are visible only inside the loop.
Saying export wordcounts does not help.
Alas, I seem to need the pipe and the while read part, so the ways to rewrite the code above with for not what I'm looking for.
Is there a legitimate way to update the shape of an associative array in a loop or even in a subshell?
source share