From c01517925d8de94b19d4ebecf66a6c055d64d63d Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Wed, 23 Sep 2015 18:48:11 +0800 Subject: [PATCH] Remove quotes from subshell call in bash script Always no quotes for $() statement. We don't need quotes to hold blanks in result: # i=$(echo 1 2 3) # echo $i 1 2 3 # These quotes can make something wrong in some case: # i=$(echo '!') # # i="$(echo '!')" -bash: !: event not found # No real problem for current code, only to use a better code style. Change-Id: I5909636bdc8de3d44a305d033c8c892af446acf3 Signed-off-by: Zhao Lei --- .../install.d/dhcp-all-interfaces.sh | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh index bd094a62f..9acb1ce2d 100755 --- a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh +++ b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh @@ -63,7 +63,8 @@ function config_exists() { function inspect_interface() { local interface=$1 - local mac_addr_type="$(cat /sys/class/net/${interface}/addr_assign_type)" + local mac_addr_type + mac_addr_type=$(cat /sys/class/net/${interface}/addr_assign_type) echo -n "Inspecting interface: $interface..." if config_exists $interface; then @@ -72,25 +73,20 @@ function inspect_interface() { echo "Device has generated MAC, skipping." else ip link set dev $interface up &>/dev/null - HAS_LINK="$(get_if_link $interface)" - TRIES=10 - while [ "$HAS_LINK" == "0" -a $TRIES -gt 0 ]; do - HAS_LINK="$(get_if_link $interface)" - if [ "$HAS_LINK" == "1" ]; then - break - else - sleep 1 - fi - TRIES=$(( TRIES - 1 )) + local has_link + local tries + for ((tries = 0; tries < 10; tries++)); do + has_link=$(get_if_link $interface) + [ "$has_link" == "1" ] && break + sleep 1 done - if [ "$HAS_LINK" == "1" ] ; then + if [ "$has_link" == "1" ]; then enable_interface "$interface" else echo "No link detected, skipping" fi fi - } if [ -n "$INTERFACE" ]; then