"how to use global arrays in bash?" Code Answer


the | while read element; do ... done is running in a sub-shell, so its updates to the global are lost when the sub-shell exits.

one solution is to use bash's 'process substitution' to get the input to the while loop to run in a subshell instead. see: reading multiple lines in bash without spawning a new subshell?

By tinyproxy on May 11 2022

Answers related to “how to use global arrays in bash?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.