vi function11.sh
#!/bin/bash
text="global variable"
#函數中使用的局部變量和全局變量的名字相同
use_local_var_fun()
{
local text="local variable"
echo "In function use_local_var_fun"
echo $text
}
#輸出函數use_local_var_fun內部的局部變量
echo "Execute the function use_local_var_fun"
use_local_var_fun
#輸出函數use_local_var_fun外的全局變量值
echo "Out of function use_local_var_fun"
echo $text
exit 0
./function11.sh
Execute the function use_local_var_fun
In function use_local_var_fun
local variable
Out of function use_local_var_fun
global variable