]> git.ipfire.org Git - thirdparty/libvirt.git/commit
libvirt-guests.sh: Declare and assign separately to avoid masking return values
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Jan 2026 10:28:47 +0000 (11:28 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Jan 2026 13:21:57 +0000 (14:21 +0100)
commit8f0cf96b66b5f34f1134b3ff4e76a7cb1c3cfbb6
tree7ebcd549d2109329dd4b531accff521f3b312a71
parent7a0c2fba91e093347147584f2ba7800f94ad3adc
libvirt-guests.sh: Declare and assign separately to avoid masking return values

In Bash, the following code does not do what you think it does:

  func() {
      local var=$(false)
      echo $?
  }

Here, '0' is echoed even though false is designed to exit with a
non-zero code. This is because in fact the last executed command
is 'local' not 'false' and thus '$?' contains zero as in "yeah,
the variable is successfully declared" [1]. In our libvirt-guest
shell script, there are a few places like this. Fix them.

1: bash_builtins(1)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/libvirt-guests.sh.in