Skip to content

read builtin detects if `stdin` is a TTY

Michael Aaron Murphy requested to merge huntergoldstein:read_for_tty into master

Created by: huntergoldstein

Changes introduced by this pull request:

  • Added sys::isatty which emulates libc's isatty
  • read builtin detects if stdin is a TTY: if so, it uses liner, otherwise it reads line by line assigning each new variable to each line

Drawbacks: If we have input like:

Foo
Bar
Baz

and call

$ read foo bar < input

The last line of input will be lost. Is this desirable? Or should we make like Bash's read which uses the last variable as the sink for remaining input. If so, we could make it an array of lines.

Fixes: Closes #474 (closed). Disclaimer: this does not resolve all issues mentioned in the issue i.e.:

echo "foo" | read bar

will do nothing as read bar is executed in a subshell.

State: Good to go barring the issue mentioned in Drawbacks

Merge request reports