使用局部变量.sh Shell 脚本

Shell 片段 · codes/shell/脚本函数/使用局部变量.sh · 22 行

源码

#!/usr/bin/env bash

# demonstrating the local keyword

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

temp=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;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。