From ef1ff1b4f29762d1caf83dc2b65ccfc7cb96e140 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 10 Nov 2011 21:46:08 -0500 Subject: make shell math operations style more succulent Convert the style: var=$((${var} + 1)) to: : $(( var += 1 )) The latter is easier to read imo. Signed-off-by: Mike Frysinger --- net/ifconfig.sh.Linux.in | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'net/ifconfig.sh.Linux.in') diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in index a5540c03..dcbd6286 100644 --- a/net/ifconfig.sh.Linux.in +++ b/net/ifconfig.sh.Linux.in @@ -26,7 +26,7 @@ _ifindex() { local line= i=-2 while read line; do - i=$((${i} + 1)) + : $(( i += 1 )) [ ${i} -lt 1 ] && continue case "${line}" in "${IFACE}:"*) echo "${i}"; return 0;; @@ -34,7 +34,7 @@ _ifindex() done < /proc/net/dev # Return the next available index - i=$((${i} + 1)) + : $(( i += 1 )) echo "${i}" return 1 } @@ -96,7 +96,7 @@ _get_inet_addresses() _exists || break local addr="$(_get_inet_address)" [ -n "${addr}" ] && addrs="${addrs}${addrs:+ }${addr}" - i=$((${i} + 1)) + : $(( i += 1 )) done echo "${addrs}" } @@ -106,26 +106,26 @@ _cidr2netmask() local cidr="$1" netmask="" done=0 i=0 sum=0 cur=128 local octets= frac= - local octets=$((${cidr} / 8)) - local frac=$((${cidr} % 8)) + local octets=$(( cidr / 8 )) + local frac=$(( cidr % 8 )) while [ ${octets} -gt 0 ]; do netmask="${netmask}.255" - octets=$((${octets} - 1)) - done=$((${done} + 1)) + : $(( octets -= 1 )) + : $(( done += 1 )) done if [ ${done} -lt 4 ]; then while [ ${i} -lt ${frac} ]; do - sum=$((${sum} + ${cur})) - cur=$((${cur} / 2)) - i=$((${i} + 1)) + : $(( sum += cur )) + : $(( cur /= 2 )) + : $(( i += 1 )) done netmask="${netmask}.${sum}" - done=$((${done} + 1)) + : $(( done += 1 )) while [ ${done} -lt 4 ]; do netmask="${netmask}.0" - done=$((${done} + 1)) + : $(( done += 1 )) done fi @@ -150,7 +150,7 @@ _add_address() # Get the last alias made for the interface and add 1 to it i=$(ifconfig | sed '1!G;h;$!d' | grep -m 1 -o "^${iface}:[0-9]*" \ | sed -n -e 's/'"${iface}"'://p') - i=$((${i:-0} + 1)) + : $(( i = ${i:-0} + 1 )) iface="${iface}:${i}" fi -- cgit v1.2.3