In the scenario where both script1.sh and script2.sh contain a function with the same name but different definitions, and script2.sh is sourced in script1.sh, if the function is executed from script1.sh. Which function will be invoked?
I tried to simulate this case. If the function is executed from script1.sh, it is using the function defined in script1.sh only. However, is this behavior consistent across all cases?
script1.sh
#!/bin/bash
source script2.sh
execute() {
echo "Hello"
}
execute
script2.sh
#!/bin/bash
execute() {
echo "Something"
}
source
is more like the C preprocessor#include
directive than it is like animport
statement.