linux-tutorial/codes/shell/脚本函数/使用局部变量.sh

22 lines
263 B
Bash
Raw Normal View History

2019-10-29 18:22:19 +08:00
#!/usr/bin/env bash
2019-05-10 11:17:57 +08:00
# demonstrating the local keyword
function func1 {
2019-10-29 18:22:19 +08:00
local temp=$[ $value + 5 ]
result=$[ $temp * 2 ]
2019-05-10 11:17:57 +08:00
}
temp=4
value=6
func1
echo "The result is $result"
if [ $temp -gt $value ]
then
2019-10-29 18:22:19 +08:00
echo "temp is larger"
2019-05-10 11:17:57 +08:00
else
2019-10-29 18:22:19 +08:00
echo "temp is smaller"
2019-05-10 11:17:57 +08:00
fi