Skip to content

interp: reading from file redirection in while loops waits indefinitely #1099

@andrewimeson

Description

@andrewimeson

In v3.9.0 of the gosh interpreter there is an issue with reading from file or file substitutions in while loops. The script just hangs when attempting to read from a file or file substitution.

This did work recently. I haven't narrowed down the exact version it broke in yet. I discovered this through it breaking in my Taskfile usage.

Examples

Works: Reading from pipe

#!/usr/bin/env gosh
set -x

echo "hi pipe" | while read -r line; do
    echo "$line"
done

echo "done"

Hangs: Reading from file

#!/usr/bin/env gosh
set -x

echo "hi file" > hi.txt

while read -r line; do
    echo "$line"
done < hi.txt

echo "done"

results in this hanging forever

$ ./while_issue.sh
+ echo 'hi file'
+ read '-r line'
+ echo 'hi file'
hi file
+ read '-r line'

Hangs: Reading from file substitution

#!/usr/bin/env gosh
set -x

while read -r line; do
    echo "$line"
done < <(echo "hi file substitution")

echo done

results in this hanging forever

$ ./while_issue.sh
+ read '-r line'
+ echo 'hi file substitution'
+ echo 'hi file substitution'
hi file substitution
+ read '-r line'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions