Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test -t 1 returns true when not attached to tty #4766

Closed
zx8 opened this issue Mar 1, 2018 · 2 comments
Closed

test -t 1 returns true when not attached to tty #4766

zx8 opened this issue Mar 1, 2018 · 2 comments
Labels
bug Something that's not working as intended
Milestone

Comments

@zx8
Copy link

zx8 commented Mar 1, 2018

Fish

$ fish --version
fish, version 2.7.1-836-g6f1ae79a

$ function is_attached_to_terminal; test -t 1; and echo yes; or echo no; end

$ echo | is_attached_to_terminal | cat
yes

Bash

$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin15.6.0)

$ is_attached_to_terminal() { test -t 1 && echo yes || echo no; }

$ echo | is_attached_to_terminal | cat
no
@faho
Copy link
Member

faho commented Mar 1, 2018

Yup. Duplicate of #1228. Either use isatty or command test.

@faho faho closed this as completed Mar 1, 2018
@faho faho added the duplicate label Mar 1, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
@faho
Copy link
Member

faho commented Sep 16, 2020

Okay, I'm going to reopen this one and then fix it separately from #1228.

The reason for that is that I'm not going to make test actually redirect these file descriptors, because that's a complete waste.

Instead, I'm going to have test check what you mean, which is if the stream goes to a terminal even if the fd doesn't.

And that's a much bigger problem with the actual device files because there are a bunch of them and I don't want to parse them out. To a first approximation, nobody cares what test -c /dev/fd/0 does. They care if stdin is a tty, and test -t 0 or isatty stdin are the thing to check.

If anyone cares enough to fiddle with /dev/fd/x and /dev/stdout and such, be my guest.

@faho faho reopened this Sep 16, 2020
@fish-shell fish-shell unlocked this conversation Sep 16, 2020
@faho faho added bug Something that's not working as intended and removed duplicate labels Sep 16, 2020
@faho faho added this to the fish 3.2.0 milestone Sep 16, 2020
@faho faho closed this as completed in 709e91c Sep 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants