[user@server]# ./functions-and-variables.sh
Local Variable value before calling function1 = Australia
Local Variable value during calling function1 = NewZealand
Local Variable value after calling function1 = Australia
Global Variable value before calling function1 = Earth
Global variable value during calling function1 = Mars
Global Variable value after calling function1 = Mars
[user@server]# cat functions-and-variables.sh
#!/bin/bash
country=Australia
planet=Earth
function local_var_function {
local country=NewZealand
echo "Local Variable value during calling function1 = $country "
}
echo "Local Variable value before calling function1 = $country "
local_var_function
echo "Local Variable value after calling function1 = $country "
function global_var_function {
planet=Mars #changing the global variable
echo "Global variable value during calling function1 = $planet "
}
echo "Global Variable value before calling function1 = $planet "
global_var_function
echo "Global Variable value after calling function1 = $planet "