linux-tutorial/codes/shell/示例脚本/脚本函数/使用全局变量带来的问题.sh

22 lines
267 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# demonstrating a bad use of variables
function func1 {
2019-10-10 08:56:31 +08:00
temp=$[ $value + 5 ]
result=$[ $temp * 2 ]
2019-05-10 11:17:57 +08:00
}
temlp=4
value=6
func1
echo "The result is $result"
if [ $temp -gt $value ]
then
2019-10-10 08:56:31 +08:00
echo "Temp is larger"
2019-05-10 11:17:57 +08:00
else
2019-10-10 08:56:31 +08:00
echo "temp is smaller"
2019-05-10 11:17:57 +08:00
fi