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