diff --git a/interp/builtin.go b/interp/builtin.go index 818f9f78..57b2c85b 100644 --- a/interp/builtin.go +++ b/interp/builtin.go @@ -9,7 +9,6 @@ import ( "context" "errors" "fmt" - "io" "os" "path/filepath" "strconv" @@ -604,6 +603,8 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a r.setVarString(name, val) } + // We can get data back from readLine and an error at the same time, so + // check err after we process the data. if err != nil { return 1 } @@ -966,11 +967,8 @@ func (r *Runner) readLine(ctx context.Context, raw bool) ([]byte, error) { esc = false } } - if err == io.EOF && len(line) > 0 { - return line, nil - } if err != nil { - return nil, err + return line, err } } } diff --git a/interp/interp_test.go b/interp/interp_test.go index 8a6a528a..75735571 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -2982,6 +2982,27 @@ done <<< 2`, "mapfile -t butter <