How to use global arrays in bash?

后端 未结 1 1438
我在风中等你
我在风中等你 2020-12-21 05:21

I was searching through SO and google for a solution to my problem for 2 days but I had no luck. My problem is that I have an array and I initiate its elements with 0\'s, an

相关标签:
1条回答
  • 2020-12-21 05:50

    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?

    0 讨论(0)
提交回复
热议问题