[libvirt] [PATCH 2/2] virt-aa-helper-test: avoid non-portable echo -n

Jim Meyering jim at meyering.net
Wed Apr 14 16:14:19 UTC 2010


Eric Blake wrote:
> * tests/virt-aa-helper-test (testme): Use printf instead.
> ---
>  tests/virt-aa-helper-test |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test
> index 3a2e74b..910c438 100755
> --- a/tests/virt-aa-helper-test
> +++ b/tests/virt-aa-helper-test
> @@ -112,10 +112,10 @@ testme() {
>          fi
>      fi
>
> -    echo -n "  $outstr: " >$output
> -    echo -n " '$extra_args $args" >$output
> +    printf "  $outstr: " >$output
> +    printf " '$extra_args $args" >$output

These are fine if you know that the printf arguments
never (and will never) contain the likes of "%" and "\".
If you add a "%s" argument, then we don't even have to think about it:

       printf %s "  $outstr: " >$output
       printf %s " '$extra_args $args" >$output

>      if [ -n "$input" ]; then
> -        echo -n " < $input" >$output
> +        printf " < $input" >$output
>      fi
>      echo "': " >$output
>      set +e
> @@ -131,7 +131,7 @@ testme() {
>      else
>          echo "FAIL: exited with '$rc'" >$output
>          echo "FAIL: exited with '$rc'"
> -        echo -n "  $outstr: "
> +        printf "  $outstr: "
>          echo " '$extra_args $args': "
>          errors=$(($errors + 1))
>          #exit $rc




More information about the libvir-list mailing list