qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] configure: silence 'shift' error message in version_ge()


From: Eric Blake
Subject: Re: [PATCH] configure: silence 'shift' error message in version_ge()
Date: Fri, 21 Aug 2020 13:09:02 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 8/21/20 10:21 AM, Peter Maydell wrote:
On Fri, 21 Aug 2020 at 16:00, Stefano Garzarella <sgarzare@redhat.com> wrote:

If there are less than 2 arguments in version_ge(), the second shift
prints this error:
     ../configure: line 232: shift: shift count out of range

Let's shut it up, since we're expecting this situation.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
  configure | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 4e5fe33211..de4bd0df36 100755
--- a/configure
+++ b/configure
@@ -229,7 +229,7 @@ version_ge () {
          set x $local_ver1
          local_first=${2-0}
          # shift 2 does nothing if there are less than 2 arguments
-        shift; shift
+        shift; shift 2>/dev/null

POSIX says
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#shift

"If the n operand is invalid or is greater than "$#", this may be
considered a syntax error and a non-interactive shell may exit"

so I think that we need to actually avoid the excess shift,
not just suppress any warning it might print. (I'm not sure
Philippe's "shift || shift" patch can work for that, though,
as the exit status doesn't distinguish "valid shift but don't
do it again" from "valid shift and more args to come".)

Indeed. 'shift || shift' is not going to work. 'shift; shift 2>/dev/null' is risky, as it can cause the shell to exit. But this does exactly what you want:

shift ${2:+2}

which works out to 'shift 2' if $2 is set, or 'shift' (implicitly shift 1) if $2 is not set.


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]