You are not logged in.
Hello,
I'm using the latest Arch Linux and I was trying to understand how I can detect if I'm working in TTY or GUI environment.
I read several resoruces on Internet, for example https://unix.stackexchange.com/question … a-terminal but in my case, when I write "test -t 0 -a -t 1 -a -t 2" while I have on TTY environment (CTRL+ALT+F2), I don't get any output.
Why would I like to know this? Because I would like to change the SHELL prompt in case I'm in TTY or I'm using a terminal. I'm using BASH and FISH as shell.
For BASH, I was thinking to put an if statement on .bashrc for PS1, but, it seems I'm not able to differentiate the two environments.
For FISH, I was thinking to use isatty (as explained in its docs https://fishshell.com/docs/current/cmds/isatty.html) but on TTY each example command on the docs I run, it does not produce any output.
Is there an efficient way to do this?
Last edited by D3vil0p3r (2023-05-27 12:59:23)
Offline
Use tty(1). A GUI shell will return /dev/pts/whatever whereas a console will return /dev/ttyX.
EDIT: but ssh & co. will return /dev/pts/, if that matters.
Last edited by Head_on_a_Stick (2023-05-27 11:42:16)
Jin, Jîyan, Azadî
Offline
... when I write "test -t 0 -a -t 1 -a -t 2" while I have on TTY environment (CTRL+ALT+F2), I don't get any output.
What output do you expect to get? Did you take a moment to think about what that command does before you ran it (or read the very simple and clear man page for test)? `test` tests, it doesn't generate output but just returns an exit status. But that's a pretty useless test anyways - it says nothing about whether the terminal is an actuall vt vs a (gui) pty - it will return a true value in both cases if all the standard streams have not been closed / redirected, and it will return false in both cases if any of the streams have been closed / redirected. To be fair, this is exactly what the questioner of the linked thread was looking for - but it's not at all related to your question.
Use tty as noted above.
Last edited by Trilby (2023-05-27 12:38:28)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Hello. I solved the issue by using the suggestion of @Head_on_a_Stick
Thank you guys.
Offline