shell 全局和局部变量
2016-02-24 17:18
447 查看
/******************************************************************** * shell 全局和局部变量 * 声明: * 到目前为止,在写shell脚本的时候,经常被shell的函数中的变量 * 作用域搞得糊涂,于是今天特意查了点资料,看到底怎么回事。 * * 2016-2-24 深圳 南山平山村 曾剑锋 *******************************************************************/ 一、参考文章: shell 函数变量调用( 全局和局部 )混淆!!! http://bbs.chinaunix.net/thread-3607361-1-1.html 二、结论: shell变量都是全局的,除非在函数中用local限定(如果你的shell支持的话) 三、测试代码: #!/bin/bash data=10 modify_data() { echo "2. $data" data=50 echo "3. $data" } echo "1. $data" modify_data echo "4. $data" 四、测试结果: 1. 10 2. 10 3. 50 4. 50
相关文章推荐
- PowerShell 工作流简介
- xshell无法连接centos 6.6的问题
- shell中的各种括号的使用方法
- shell遍历当前目录下的文件,用去掉文件后缀的字符串替换文件中的文本
- linux基本命令认识,shell打渠道包
- FOR循环删除文件后缀名
- linux-shell-cd
- shell 脚本替换文件中某个字符串
- bash Redirecting_AppendingRedirecting_HereDocument_HereString_etc
- 文章标题
- xshell 输入w 命令后报错 66 column window is too narrow
- bash: hadoop: command not found
- linux_shell_HERE Document
- linux shell读写mysql
- awk和shell变量交互
- linux shell中的数组和关联数组
- linux shell 字符串操作…
- shell 调用mysql存储过程
- linux shell mysql&nbsp…
- linux shell 操作mysql