There is a 2 bash script file. First file b.sh is mentioned below.
#!/bin/bash
declare -a arr1=()
func() {
var_a=12
arr1[0]=20
arr1[1]=30
declare -a arr2=()
arr2[0]=40
arr2[1]=50
}
Second file a.sh is mentioned below.
#!/bin/bash
source b.sh
func
echo $var_a
echo ${arr1[1]}
echo ${arr2[1]}
Output is
12
30
My doubt is, why the local array variable (arr2) in func is not accessible in a.sh. But the local variable var_a is accessible.
arr2andvar_a.var_ais a local variable?sourcecommand to reproduce this problem -- it could easily be created with just one.