bug-bash
[Top][All Lists]
Advanced

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

Several issues with coprocesses regarding exit status


From: DJ Mills
Subject: Several issues with coprocesses regarding exit status
Date: Tue, 11 Dec 2012 14:31:28 -0500

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -march=x86-64
-mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4
-D_FORTIFY_SOURCE=2
-DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin'
-DSTANDARD_UTILS_PATH='/usr/bin:/bin:/usr/sbin:/sbin'
-DSYS_BASHRC='/etc/bash.bashrc' -DSYS_BASH_LOGOUT='/etc/bash.bash_logout'
uname output: Linux medinvdj 3.6.9-1-ARCH #1 SMP PREEMPT Tue Dec 4 08:04:10
CET 2012 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.2
Patch Level: 39
Release Status: release



I've noticed several issues with coproc, as stated below.

1)
  First of all, the man page and help output state:
    `The return status of a coprocess is the exit status of command.'
  No matter what, coproc seems to always return true.

  To reproduce:
    coproc false || echo error1 >&2; wait "$COPROC_PID" || echo error2 >&2

  Output:
    [1] 31769
    [1]+  Exit 1                  coproc COPROC false
    error2



2)
  However, the exception to #1 is my second issue, with is that coproc
always
  seems to fail when called within the test portion of an if statement. I
have
  absolutely no idea why this happens.

  To reproduce:
    if ! coproc false; then echo error1 >&2; fi; wait "$COPROC_PID" || echo
error2 >&2

  Output:
    [1] 3971
    error1
    [1]+  Exit 1                  ! coproc COPROC false
    error2



3)
  The first two issues aren't THAT big of a deal, because you can simply not
  worry about coproc's exit status and use wait's. That leads me to the
third
  and largest issue, which is that "NAME_PID" only appears to work properly
  either when in an interactive shell or when there's no command between the
  coproc and the wait.

  To reproduce:
    #!/bin/bash

    # this one works
    coproc mycoproc { false ; }
    if ! wait "$mycoproc_PID"; then
      echo "error1" >&2
    fi

    # this one does not
    coproc mycoproc { false; }
    while read -ru "${mycoproc[0]}" line; do
      echo "coproc: $line"
    done
    if ! wait "$mycoproc_PID"; then
      echo "error2" >&2
    fi

  Output:
    error1
    script: line 14: wait: `': not a pid or valid job spec
    error2



The whole reason I'm using a coprocess instead of process substitution is
to be
able to read the output into an array while also checking the exit status.
For
the time being, I can use a named pipe, but I was rather excited about being
able to do this without having to worry about cleaning up files.


Thanks for your time, I know this was a long one.
  -DJ


reply via email to

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