-o pipefail makes while read loop ugly

Bug #1804504 reported by Thorsten Glaser
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mksh
Invalid
Medium
Thorsten Glaser

Bug Description

tc.sh:

    set -x
    set -e
    cat >tc.in <<\EOF
    one eins
    two zwei
    three drei
    EOF

    while IFS=' ' read a b; do
            # $a = t* and it works
            [[ $a = o* ]] && echo $b
    done <tc.in | sort -u >tc.out

    echo after the loop
    cat tc.out
    echo and out

This works with t* both with set ±o pipefail, and with t* in ksh93, but t* in mksh with set -o pipefail makes it error out *after* the “while” because the last comparison error’d out.

Workarounds include negating the comparison…

            [[ $a != o* ]] || echo $b

… so that the loop always has $?=0, or:

    while :; do
            IFS=' ' read a b || break

Interestingly enough, removing the “| sort -u” also makes it work.

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

This is, unfortunately, by design.

I’ve committed a manpage change (in CAVEATS) with a rationale, though.

Changed in mksh:
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.