x=1
function f()
{
    echo $x
}
x=2 f #2
function g()
{
    x=3
    a=4
    echo $x
}
a=5
x=2 g  #3
echo $x  #1
echo $a  #4
Why the output is 2 3 1 4 ? Why function f access the one line variable x rather than the global one? Why function g create global variables x and a, but the x does not override outside global one?
 
    