使用全局变量带来的问题.sh Shell 脚本

Shell 片段 · codes/shell/脚本函数/使用全局变量带来的问题.sh · 22 行

源码

#!/usr/bin/env bash

# demonstrating a bad use of variables

function func1 {
	temp=$[ $value + 5 ]
	result=$[ $temp * 2 ]
}

temlp=4
value=6

func1
echo "The result is $result"

if [ $temp -gt $value ]
then
	echo "Temp is larger"
else
	echo "temp is smaller"
fi

查看上游源码 ↗

内容与示例整理自 dunwu/linux-tutorial,遵循 CC BY-SA 4.0;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。