Linux shell之全局变量和局部变量

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

posted @ 2021-04-09 18:37  zhudaheng123  阅读(981)  评论(0)    收藏  举报