/******************************************************************** * Shell Global and local variables * declaration: * To So far, when writing shell scripts, often by the shell function in the variable * scope confused, so today deliberately looked up a bit of information, see what is going on. * 2016-2-24 Shenzhen Nanshan Ping Shan village Zengjianfeng *************************************************************** ****/One, reference article: Shell function variable call (global and local) confusion!!! http://bbs.chinaunix.net/thread-3607361-1-1.htmlii. Conclusion: Shell variables are global unless you use local qualification in a function (if your shell supports it). Test code: #!/bin/Bash Data=TenModify_data () {echo"2. $data"Data= -Echo"3. $data"} Echo"1. $data"Modify_data Echo"4. $data"iv. test Results:1.Ten 2.Ten 3. - 4. -
Shell Global and local variables