shell 中的${},##, %% , :- ,:+, ? 的使用 - 30岁再次出发 - 博客园
a.sh
#!/bin/sh
jsonfilter() {
echo 999999999999999
echo "1= ${1} 2 = ${2} 3=${3} 4=${4} 5= ${5} 6=${6}"
}
__network_ifstatus() {
jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "$__NETWORK_CACHE" -e "$1=@.interface${2:+[@.interface='$2']}$3"
}
#echo 88888888888888888
#__network_ifstatus "extiface" "" "[@.route[@.target='0.0.0.0' && !@.table]].interface" "88888888888888" 1
# 1: destination variable
# 2: addr
# 3: inactive
__network_wan()
{
__network_ifstatus "$1" "" \
"[@.route[@.target='$2' && !@.table]].interface" "" 1 && \
return 0
[ "$3" = 1 -o "$3" = "true" ] && \
__network_ifstatus "$1" "" \
"[@.inactive.route[@.target='$2' && !@.table]].interface" "" 1
}
# find the logical interface which holds the current IPv4 default route
# 1: destination variable
# 2: consider inactive default routes if "true" (optional)
network_find_wan() { __network_wan "$1" "0.0.0.0" "$2"; }
network_find_wan extiface
执行 a.sh
jj@ubuntu-rd540-3:~/tmp/jsonfilter$ ./a.sh
999999999999999
1= -l 2 = 1 3=-s 4= 5= -e 6=extiface=@.interface[@.route[@.target='0.0.0.0' && !@.table]].interface