Reputation: 2541
I'm trying to echo the type of the current terminal being ran. For instance If I was running konsole then it would echo konsole. I've tried running
echo $TERM
But that prints out xterm every time. Is there a better and more accurate way of doing this?
Upvotes: 2
Views: 433
Reputation: 123608
pstree
can help.
$ pstree -s $$
init───gnome-terminal───bash───pstree
The -s
option shows parents of the specified process.
In bash (and Bourne-shell variants), $$
denotes the PID of the current shell.
Another invocation (while running from xterm
returns):
$ pstree -s $$
init───xterm───bash───pstree
Specifying the -A
option makes pstree
use ASCII characters so that you can parse the output easily:
$ pstree -A -s $$
init---gnome-terminal---bash---pstree
Upvotes: 6