diff --git a/hooks/install b/hooks/install
index 0351885cc320ce6c68df3add4dafd603d6f4d211..227d4df879fd4c82eae9e4384463498887e52ddb 100644
--- a/hooks/install
+++ b/hooks/install
@@ -21,25 +21,21 @@ RELEASE_MAJOR="$( echo $DISTRIB_RELEASE | awk -F '.' '{print $1}' )"
 
 if [ "$RELEASE_MAJOR" -le "16" ]; then
     # Ubuntu release is less or equal than trusty
-    # copy metric 0 routes to routes with metric 1
-    ip route show | grep "^default" | grep -v metric | while read line; do
-        ip route append $line metric 1 || true
-    done
-    # delete metric 0 routes
-    ip route show | grep "^default" | grep -v metric | while read line; do
-        ip route del $line metric 0
-    done
+    defaultroutecommand="ip route show | grep ^default | grep -v metric"
 else
-    # copy metric 0 routes to routes with metric 1
-    ip route show default metric 0 | while read line; do
-        ip route append $line metric 1 || true
-    done
-    # delete metric 0 routes
-    ip route show default metric 0 | while read line; do
-        ip route del $line metric 0
-    done
+    defaultroutecommand="ip route show default metric 0"
 fi
 
+# copy metric 0 routes to routes with metric 1
+eval $defaultroutecommand | while read line; do
+    ip route append $line metric 1 || true
+done
+
+# delete metric 0 routes
+eval $defaultroutecommand | while read line; do
+    ip route del $line metric 0
+done
+
 # add our route
 if ip route replace default via $GATEWAY_IP metric 0; then
     juju-log "Default gateway set"