Hello. The question is the following. Suppose I in the recursive function rec, write the following definition of an array: local dep = ('cat $ 1') (backticks naturally) so I’ll mix the entire contents of the file into an array. Then I call rec again, whether the initial value of the array will be restored after returning, just like in C and C ++, because the differences only in the syntax of filling the array, in both cases, using local, the variable or array is saved on the stack in this case, this assumption?

Thank you for your reply.

  • and most difficult to check? - sercxjo
  • at the moment I find it difficult for technical reasons, I thought someone would tell. - Ilya.K.

1 answer 1

Here is an example with an array of two elements.

#!/bin/bash f(){ local x x=($x $1 $2) echo ${x[*]} [ $1 -lt 4 ] && f $(($1+1)) $2 echo ${x[*]} } f 1 2 

Judging by the conclusion

 1 2 2 2 3 2 4 2 4 2 3 2 2 2 1 2 

arrays are stored in each call their own.

If local remove the array common changes

 1 2 1 2 2 1 3 2 1 4 2 1 4 2 1 4 2 1 4 2 1 4 2 
  • Great, thank you. - Ilya.K.