I have the following script called .bash_functions.test
which is already sourced by my .bash_functions
script:
# vim: set syn=sh noet:
mp4Options_BIS="-movflags +frag_keyframe"
declare -A audioExtension=( [libspeex]=spx [speex]=spx [opus]=opus [vorbis]=ogg [aac]=m4a [mp3]=mp3 [mp2]=mp2 [ac3]=ac3 [wmav2]=wma [pcm_dvd]=wav [pcm_s16le]=wav )
function test1 {
echo "=> mp4Options_BIS = $mp4Options_BIS"
echo "=> audioExtension = ${audioExtension[*]}"
}
And when I run the test1
function I see this:
=> mp4Options_BIS = -movflags +frag_keyframe
=> audioExtension =
Finally, when I source the script once more and re-run the test1
function I see this:
=> mp4Options_BIS = -movflags +frag_keyframe
=> audioExtension = ac3 wma opus mp3 wav mp2 wav spx m4a spx ogg
In fact, I use my Source
function in the first source call and the source
builtin and the second source call:
$ grep -r .bash_functions.test
.bash_functions:source $initDir/.bash_functions.test
$ type Source
Source is a function
Source ()
{
test "$debug" -gt 0 && time source "$@" && echo || source "$@"
}
And here is what happens:
$ Source .initBash/.bash_functions.test
$ test1
=> mp4Options_BIS = -movflags +frag_keyframe
=> audioExtension =
$ source .initBash/.bash_functions.test
$ test1
=> mp4Options_BIS = -movflags +frag_keyframe
=> audioExtension = ac3 wma opus mp3 wav mp2 wav spx m4a spx ogg
Why is it working like this?
.bash_functions
source.bash_functions.test
from within a function by any chance? If that was the case, thedeclare
would cause that associative array to be declared local to that function and you'd needdeclare -gA
to make sure the variable is declared in the global scope. – Stéphane Chazelas Aug 15 '19 at 08:10