But this seems to work

kerrin@kerrin-HP-Z620-Workstation:~/ce_build$ echo "kvm_intel xxx" | grep -q -e 
^kvm_amd -e ^kvm_intel; echo $?
0

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to bash in Ubuntu.
https://bugs.launchpad.net/bugs/1394136

Title:
  if statement with pipe to grep randomly fails if pipefail is set

Status in “bash” package in Ubuntu:
  Confirmed

Bug description:
  The following bash script will fail randomly on trusty but when tested
  on saucy it worked all the time. On the system we test we have kvm
  installed and the if statement should evaluate to false and we should
  see ten PASS lines and no Error. And this should happen all the time.

  ======
  #!/bin/bash 

  set -eu
  set -o pipefail

  if ! lsmod | grep -q -e ^kvm_intel -e ^kvm_amd ; then
      echo 'Error: check that virtualisation is enabled in your BIOS'
  else
      echo "PASS"
  fi
  =======

  As can be seen if I run it 10 times I get 2 PASS and 8 failures

  =======
  kerrin@kerrin-HP-Z620-Workstation:~/ce_build$ for i in $(seq 0 9) ; do bash 
test-simple.bash ; done
  PASS
  PASS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  Error: check that virtualisation is enabled in your BIOS
  =======

  Now if I turn off the pipefail then the script passes all the time and
  just prints out 10 PASS lines.

  The script uses bash, grep and lsmod and I have the following versions
  on trusty of them

  kerrin@kerrin-HP-Z620-Workstation:~/ce_build$ dpkg -l | grep bash
  ii  bash                                                  4.3-7ubuntu1.5      
                                amd64        GNU Bourne Again SHell
  ii  bash-completion                                       1:2.1-4             
                                all          programmable completion for the 
bash shell
  ii  command-not-found                                     0.3ubuntu12         
                                all          Suggest installation of packages 
in interactive bash sessions
  kerrin@kerrin-HP-Z620-Workstation:~/ce_build$ dpkg -l | grep grep
  ii  grep                                                  2.16-1              
                                amd64        GNU grep, egrep and fgrep
  kerrin@kerrin-HP-Z620-Workstation:~/ce_build$ dpkg -l | grep kmod
  ii  kmod                                                  15-0ubuntu6         
                                amd64        tools for managing Linux kernel 
modules
  ii  libkmod2:amd64                                        15-0ubuntu6         
                                amd64        libkmod shared library
  ii  module-init-tools                                     15-0ubuntu6         
                                all          transitional dummy package 
(module-init-tools to kmod)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1394136/+subscriptions

-- 
Mailing list: https://launchpad.net/~touch-packages
Post to     : touch-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~touch-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to