Jesse Hathaway
2018-11-12 15:20:01 UTC
I ran into a strange issue last week when attempting to pipe some
output into a bash function. The function would always return with an
error code of 127. I was able to narrow the cause down my use of the
`lastpipe` option. When I run the below minimal test case without
`lastpipe`, it completes successfully, but when I use `lastpipe`, the
function returns an error code of 127. I ran the failing program
through strace and it appeared the problem might be due to a wait
system call that doesn't find any matching pids? Any help would be
greatly appreciated, i'm stumped.
; cat lastpipe
#!/bin/bash
set -o pipefail
function bubbles() {
cat | cat
date
}
if echo 'butter' | bubbles; then
echo "SUCCESS: $?"
else
echo "FAILED: $?"
fi
; bash lastpipe
butter
Mon Nov 12 09:10:13 CST 2018
SUCCESS: 0
; bash -O lastpipe lastpipe
butter
Mon Nov 12 09:10:20 CST 2018
FAILED: 127
output into a bash function. The function would always return with an
error code of 127. I was able to narrow the cause down my use of the
`lastpipe` option. When I run the below minimal test case without
`lastpipe`, it completes successfully, but when I use `lastpipe`, the
function returns an error code of 127. I ran the failing program
through strace and it appeared the problem might be due to a wait
system call that doesn't find any matching pids? Any help would be
greatly appreciated, i'm stumped.
; cat lastpipe
#!/bin/bash
set -o pipefail
function bubbles() {
cat | cat
date
}
if echo 'butter' | bubbles; then
echo "SUCCESS: $?"
else
echo "FAILED: $?"
fi
; bash lastpipe
butter
Mon Nov 12 09:10:13 CST 2018
SUCCESS: 0
; bash -O lastpipe lastpipe
butter
Mon Nov 12 09:10:20 CST 2018
FAILED: 127