[pve-devel] [RFC PATCH pve-manager] bridgevlanport: replace sed pipe with substitution

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Aug 10 11:48:52 CEST 2015


The previous code stripped *all* combinations of zero or
more letters and digits followed by a dot of an interface
name to retrieve the VLANID. At the same time the supposedly
opposite code for IF_VLAN_RAW_DEVICE only actually extracts
the part up to the *first* dot. Thus an interface named
'a.b.0' would have a VLANID of 0 and a raw device name of
just 'a'.
I also don't see a reason to limit the removed portions to
alphanumeric characters. I.e. an interface named tap-test.0
would result in a VLANID of 'tap-0' and an
IF_VLAN_RAW_DEVICE of 'test'.

A simple shell substitution seems to do a much better job
and is more efficient than forking out two processes with a
pipe.
---
 bridgevlanport | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bridgevlanport b/bridgevlanport
index 6f7ec5d..921890f 100755
--- a/bridgevlanport
+++ b/bridgevlanport
@@ -8,8 +8,8 @@ fi
 if [ "$MODE" = "start" ] ; then
   case "$IFACE" in
     *.[0-9]*)
-      VLANID=`echo $IFACE|sed "s/[a-zA-Z0-9]*\.//g"`
-      IF_VLAN_RAW_DEVICE=`echo $IFACE|sed "s/\([a-zA-Z0-9]*\)\..*/\1/"`
+      VLANID="${IFACE##*.}"
+      IF_VLAN_RAW_DEVICE="${IFACE%.*}"
     ;;
   esac
 
-- 
2.1.4





More information about the pve-devel mailing list