Skip to contentSkip to conversation

configure: silence 'shift' error message in version_ge()

PATCH Superseded Stefano Garzarella 5 participants 7 messages Aug 21, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: silence 'shift' error message in version_ge()

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.

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
index 4e5fe33211..de4bd0df36 100755
@@ -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
         local_ver1=$*
         set x $local_ver2
         # the second argument finished, the first must be greater or equal
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Stefano Garzarella

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.

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index 4e5fe33211..de4bd0df36 100755

configure version_ge () { · line 235

Quoted 8 lines
configure +1 -1
@@ -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
         local_ver1=$*
         set x $local_ver2
         # the second argument finished, the first must be greater or equal
#2 lore raw
In reply to Stefano Garzarella
Quoted 17 lines · Stefano Garzarella

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.

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index 4e5fe33211..de4bd0df36 100755

configure version_ge () { · line 232

Quoted 5 lines
configure +1 -1
@@ -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".)

thanks
-- PMM

#3 lore raw
Quoted 27 lines · Peter Maydell
Quoted 17 lines · Stefano Garzarella

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.

---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index 4e5fe33211..de4bd0df36 100755

configure version_ge () { · line 232

Quoted 5 lines
configure +1 -1
@@ -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

Quoted 4 lines

"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,

Maybe something like this:

configure +1 -1
index de4bd0df36..5f5f370e2c 100755
@@ -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; test $# -gt 0 && shift
         local_ver1=$*
         set x $local_ver2
         # the second argument finished, the first must be greater or equal
Quoted 4 lines

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".)

I tried and also if I have meson 0.55.0, with the Philippe's patch applied it tries to download our internal meson, so maybe it is not working as expected.

Thanks,
Stefano

#4 lore raw
Quoted 8 lines · Stefano Garzarella
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Stefano Garzarella

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.

Maybe s/shut up/silence/?

Quoted 32 lines
Quoted 20 lines
Quoted 11 lines
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index 4e5fe33211..de4bd0df36 100755

configure version_ge () { · line 232

Quoted 5 lines
configure +1 -1
@@ -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

Quoted 4 lines

"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,

Maybe something like this:

configure +0 -0
index de4bd0df36..5f5f370e2c 100755

configure version_ge () { · line 232

Quoted 5 lines
configure +1 -1
@@ -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; test $# -gt 0 && shift

This looks better that mine indeed.

Quoted 4 lines
configure +0 -0
         local_ver1=$*
         set x $local_ver2
         # the second argument finished, the first must be greater or equal
Quoted 8 lines
Quoted 4 lines

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".)

I tried and also if I have meson 0.55.0, with the Philippe's patch applied it tries to download our internal meson, so maybe it is not working as expected.

=)

Quoted 4 lines

Thanks,
Stefano

#5 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Stefano Garzarella
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Stefano Garzarella

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.

Maybe s/shut up/silence/?

Yeah, less aggressive ;-)

Quoted 28 lines
Quoted 28 lines
Quoted 21 lines
Quoted 12 lines
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index 4e5fe33211..de4bd0df36 100755

configure version_ge () { · line 232

Quoted 5 lines
configure +1 -1
@@ -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

Quoted 4 lines

"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,

Maybe something like this:

Quoted 12 lines

configure version_ge () { · line 232

Quoted 10 lines
configure +1 -1
index de4bd0df36..5f5f370e2c 100755
@@ -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; test $# -gt 0 && shift

This looks better that mine indeed.

Okay, I'll send a v2 with this change.

Thanks,
Stefano

Quoted 21 lines
Quoted 5 lines
configure +0 -0
         local_ver1=$*
         set x $local_ver2
         # the second argument finished, the first must be greater or equal
Quoted 8 lines
Quoted 4 lines

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".)

I tried and also if I have meson 0.55.0, with the Philippe's patch applied it tries to download our internal meson, so maybe it is not working as expected.

=)

Quoted 4 lines

Thanks,
Stefano

#6 lore raw
In reply to Peter Maydell
Quoted 27 lines · Peter Maydell
Quoted 17 lines · Stefano Garzarella

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.

---
  configure | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
configure +0 -0
index 4e5fe33211..de4bd0df36 100755

configure version_ge () { · line 232

Quoted 5 lines
configure +1 -1
@@ -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

Quoted 8 lines

"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.

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