1.以openwrt中的/etc/hotplug.d/button/00-button为例
. /lib/functions.sh
do_button () {
local button ---- 定义局部变量
local action
local handler
local min
local max
config_get button $1 button
config_get action $1 action
config_get handler $1 handler
config_get min $1 min
config_get max $1 max
[ "$ACTION" = "$action" -a "$BUTTON" = "$button" -a -n "$handler" ] && {
[ -z "$min" -o -z "$max" ] && eval $handler
[ -n "$min" -a -n "$max" ] && {
[ $min -le $SEEN -a $max -ge $SEEN ] && eval $handler
}
}
//解释:
[ ] --- 判断条件,如果里面的结果为真,再执行后面的处理
= --- 值是否相等
-a 逻辑与
-n 变量是否存在
-z 变量是否不存在
-o 逻辑或
-le less than & equal
-ge great than & equal
}
config_load system
config_foreach do_button button