`test` 命令的 `-t` 运算符不能正确识别非 tty 文件描述符

the `-t` operator for the `test` command does not correctly identify non-tty file descriptors

在bash/ksh/dash中:

$ input_redirected() { [[ -t 0 ]] && echo input is not redirected || echo input is redirected; }
$ input_redirected foo
input is not redirected
$ input_redirected < /dev/null
input is redirected
$ cat /etc/passwd | input_redirected
input is redirected

在鱼中

$ function input_redirected; test -t 0; and echo not redirected; or echo redirected; end
$ input_redirected foo
not redirected
$ input_redirected < /dev/null
not redirected
$ cat /etc/passwd | input_redirected
not redirected

但是,使用 isatty 0 而不是 test -t 0 确实提供了预期的输出。

test -t FD 测试在鱼身上做什么,它的行为与 POSIX 类型的 shell 不同?

这是一个错误:https://github.com/fish-shell/fish-shell/issues/1228

解决方法是使用 command test,这也是 isatty 所做的 - 请参阅 type isatty