Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Bash, how can I tell if I am currently in a terminal

Tags:

bash

gnome

I want to create my own personal logfile that logs not only when I log in and out, but also when I lock/unlock my screen. Kindof like /var/log/wtmp on steroids.

To do this, I decided to run a script when I log into Ubuntu that runs in the background until I quit. My plan to do this is to add the script to .bashrc, using ./startlogging.sh & and in the script I will use trap to catch signals. That's great, except .bashrc gets run every time I open a new terminal, which is not what I want for the logger.

Is there a way to tell in Bash that the current login is a gnome login? Alternatively, is there some sort of .gnomerc I can use to run my script?

Edit: Here is my script:

Edit 2: Removed the script, since it's not related to the question. I will repost my other question, rather than repurpose this one.

like image 617
Robert Martin Avatar asked Oct 06 '22 15:10

Robert Martin


1 Answers

Are you looking for a way to detect what type of terminal it is?

Try:

echo $TERM

From Wikipedia:

TERM (Unix-like) - specifies the type of computer terminal or terminal emulator being used (e.g., vt100 or dumb).

See also: List of Terminal Emulators

like image 85
sampson-chen Avatar answered Oct 10 '22 04:10

sampson-chen