shellScript之函数中的全局变量和局部变量

#!/bin/bash
text="global variable"
use_local_var_fun()
{
    local text ="local variable"
    echo "In function use_local_var_fun"
    echo $text
}

echo "Execute the function use_local_var_fun"
use_local_var_fun
echo "out of function use_local_var_fun"
echo "$text"


结果:

~/Note/test # ./33local_to_global_var.sh 
Execute the function use_local_var_fun
./33local_to_global_var.sh: 第 5 行:local: `=local variable': 不是有效的标识符
In function use_local_var_fun

out of function use_local_var_fun
global variable


你可能感兴趣的:(shellscript)