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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM