Patchwork [1/1] runqemu: replace bashism with working shell idiom

login
register
mail settings
Submitter Peter Seebach
Date May 14, 2012, 10:49 p.m.
Message ID <48e888dd2f3cebd256476a7ddd90f2d1a88ad788.1337035611.git.peter.seebach@windriver.com>
Download mbox | patch
Permalink /patch/27743/
State Accepted
Commit 716ae8dbd1fb29292c9fca0f59d3807a54508e87
Headers show

Comments

Peter Seebach - May 14, 2012, 10:49 p.m.
The =~ operator is not one of my favorites, not just due to portability
issues, but because it's not well known, and a lot of people might
not expect a regex operator.

The canonical shell idiom for this is to use case with alternation
and wildcards.  As a side note, if you are matching anything containing
core-image-sato, you don't need to also check for core-image-sato-sdk.

Signed-off-by: Peter Seebach <peter.seebach@windriver.com>
---
 scripts/runqemu |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
Scott Garman - May 15, 2012, 2:18 a.m.
On 05/14/2012 03:49 PM, Peter Seebach wrote:
> The =~ operator is not one of my favorites, not just due to portability
> issues, but because it's not well known, and a lot of people might
> not expect a regex operator.
>
> The canonical shell idiom for this is to use case with alternation
> and wildcards.  As a side note, if you are matching anything containing
> core-image-sato, you don't need to also check for core-image-sato-sdk.
>
> Signed-off-by: Peter Seebach<peter.seebach@windriver.com>

Thank you, Peter.

Acked-by: Scott Garman <scott.a.garman@intel.com>

> ---
>   scripts/runqemu |   13 +++++++------
>   1 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/runqemu b/scripts/runqemu
> index 305e46a..fc7363f 100755
> --- a/scripts/runqemu
> +++ b/scripts/runqemu
> @@ -300,14 +300,15 @@ findimage() {
>       # recently created one is the one we most likely want to boot.
>       filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
>       for name in $filenames; do
> -        if [ "$name" =~ core-image-sato-sdk -o \
> -              "$name" =~ core-image-sato     -o \
> -              "$name" =~ core-image-lsb      -o \
> -              "$name" =~ core-image-basic    -o \
> -              "$name" =~ core-image-minimal ]; then
> +        case $name in
> +        *core-image-sato* | \
> +        *core-image-lsb* | \
> +        *core-image-basic* | \
> +        *core-image-minimal* )
>               ROOTFS=$name
>               return
> -        fi	
> +            ;;
> +        esac
>       done
>
>       echo "Couldn't find a $machine rootfs image in $where."

Patch

diff --git a/scripts/runqemu b/scripts/runqemu
index 305e46a..fc7363f 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -300,14 +300,15 @@  findimage() {
     # recently created one is the one we most likely want to boot.
     filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
     for name in $filenames; do
-        if [ "$name" =~ core-image-sato-sdk -o \
-              "$name" =~ core-image-sato     -o \
-              "$name" =~ core-image-lsb      -o \
-              "$name" =~ core-image-basic    -o \
-              "$name" =~ core-image-minimal ]; then
+        case $name in
+        *core-image-sato* | \
+        *core-image-lsb* | \
+        *core-image-basic* | \
+        *core-image-minimal* )
             ROOTFS=$name
             return
-        fi	
+            ;;
+        esac
     done
 
     echo "Couldn't find a $machine rootfs image in $where."