[Ovirt-devel] [PATCH 4/4] build-all.sh: Avoid unnecessary "grep" in IP-addr-extraction code

Jim Meyering jim at meyering.net
Mon Jun 16 08:22:06 UTC 2008


Chris Lalancette <clalance at redhat.com> wrote:

> Jim Meyering wrote:
>> diff --git a/build-all.sh b/build-all.sh
>> index eb9c848..e681f18 100755
>> --- a/build-all.sh
>> +++ b/build-all.sh
>> @@ -226,7 +226,8 @@ fi
>>  # NOTE: create-wui-appliance.sh must be run as root
>>  if [ $update_app == 1 ]; then
>>      # FIXME: This can go away once we have livecd tools building the appliances
>> -    VIRBR=$(virsh net-dumpxml default | grep "<ip address=" | sed "s/.*ip address='\(.*\)' .*/\1/")
>> +    VIRBR=$(virsh net-dumpxml default \
>> +	    | sed -n "s/.*ip address='\([^.]*\)' .*/\1/p")
>
> This is fine, but maybe we should change also then change the sed part of it to
> look for ".*<ip address='\([^.]*\)' .*" instead?  Not really a big deal anyway,
> just a minor cleanup.

Good point.

One more nit: I'll tighten it up a little more by requiring a match
at the beginning of the line with optional leading spaces:

  | sed -n "s/^ *<ip address='\([^.]*\)' .*/\1/p")

Updated patch:

>From 8c80cd62e71791a79c3623744c5b19ad3c7c43ae Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Sun, 15 Jun 2008 14:55:43 +0200
Subject: [PATCH] build-all.sh: avoid an unnecessary grep in IP-addr-extraction code

---
 build-all.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/build-all.sh b/build-all.sh
index eb9c848..f49489d 100755
--- a/build-all.sh
+++ b/build-all.sh
@@ -226,7 +226,8 @@ fi
 # NOTE: create-wui-appliance.sh must be run as root
 if [ $update_app == 1 ]; then
     # FIXME: This can go away once we have livecd tools building the appliances
-    VIRBR=$(virsh net-dumpxml default | grep "<ip address=" | sed "s/.*ip address='\(.*\)' .*/\1/")
+    VIRBR=$(virsh net-dumpxml default \
+	    | sed -n "s/^ *<ip address='\([^.]*\)' .*/\1/p")
     test -z $VIRBR && die "Could not get ip address of default network for app"

     cd $BASE/wui-appliance
--
1.5.6.rc2.47.g075fa




More information about the ovirt-devel mailing list