How can I identify the current terminal emulator from a bash script?

how to check terminal in linux
linux check current terminal emulator
shell script to display terminal number
see current terminal
how to get pid of current terminal
terminal emulators
check current terminal shell
best terminal emulator

I've got a script that will open a new tab in the OS X Terminal application and I'm trying to add support for iTerm2. Unfortunately, the methods to open tabs in the two terminal emulators are different.

How could I tell which of the two is being used, or is open, to conditionally run the correct script?

I'm not sure how to tell iTerm and iTerm2 apart, but check the $TERM_PROGRAM envar. For me (Mac OS X 10.7), it returns Apple_Terminal for Terminal.app, and iTerm.app for iTerm2.

Get the terminal emulator name inside the shell script, To find the name of the terminal emulator used by the current shell, you could ask the X window system to give you the name of the window that  There is the individual user's preferred terminal emulator, and (on some operating systems) a system-wide preferred terminal emulator. system-wide. The latter is set on Debian and derivative operating systems via its alternatives system, as x-terminal-emulator. This command will invoke, and its manual page will be the manual page of, one of a number of (installed) GUI terminal emulator programs, amongst which the system administrator can switch with the command:

You should be able to:

ps -p $$ | tail -1 | awk '{print $NF}'

command line - How do I check which terminal I am using?, 7 Answers. to find currently running shell use ls -l /proc/$$/exe. to find currently running terminal, use xprop _NET_WM_PID WM_CLASS . The value of pid later can be passed to ps -p <pid> -o args command. Technically, for terminal emulator you don't even need a command, as stated in the comments: Another script (too long) check update for every row with Internet, but i can't able to see if the process are in download mode or if script end. I would like this script open terminal and run it into the terminal, in this case i will be able to see what script are doing.

I realize this sounds sarcastic, though why didn't they title the function of "x-terminal-emulator" variably "fly-little-birdy"?

I use Linux. Once I perform a "x-terminal-emulator" function call within bash, that terminal is gone & inaccessible to my scripts.

My point is, bash needs more features for full functionality & utility. A feature of "x-terminal-emulator -attach-to-pid=TERMINAL_NAME" would be alright.

I think it's an oversight in functionality & utility. They could "fix it". :/

How to get the current terminal name?, (or console, as we oldsters use to sometimes also call it) is: /dev/tty which, can be used to easily create a new multi-line file from the command prompt thusly: cp /dev/tty README.md (hitting then puts the cursor on a new blank line where you can enter text, hit return again, Hi, I meet an problem that it cannot change Terminal environment variable in a perl or bash script. This change can only exist and become effective in script lifetime. But I want to make this change take effect in current opened Terminal. In our view, the thought seems to be impossible, As (9 Replies)

Set a terminal type or terminal emulation, A default TERM value will be set on a per-line basis by either /etc/inittab (Linux and System-V-like UNIXes) or /etc/ttys (BSD UNIXes). This will nearly always  "Exit terminal after running a bash script": Run only your script in the terminal. Without looking at the details what the script does, a script can be directly run inside a terminal with the option -e (--command), without starting a shell - it is used instead of the shell then: gnome-terminal -e ./script.sh

Find the default terminal emulator, This is a list of notable terminal emulators. Most used terminal emulators on Linux and Unix-like systems are GNOME Terminal on GNOME and GTK-based 

List of terminal emulators, Terminal emulators display a window that can be adjusted to any size from the sublime to the The 80-column default width has implications for the shell scripts and other by X and terminfo to identify the terminal type, and thus send it the correct control codes. To see the current value of the TERM variable, we can do this:

Comments
  • Do they set $TERM differently?
  • Does the "applescript" tag really apply?
  • I thought it might be an applescript solution since the tabbing solutions are.
  • @MrDaniel: Hmm, maybe. If they did set $TERM differently, it might have been a solution (though I could have phrased it better).
  • My actual answer that arguably should have been a comment was "Do they set $TERM differently?" The above comment was a comment on that answer, and it doesn't make much sense out of context.
  • The $TERM_PROGRAM envar worked great -- I only really wanted to test for iTerm.app anyway and use the Terminal.app version as the default. Thanks!
  • This only returns the shell they are running, NOT* the terminal emulator (e.g. xterm... )
  • What would as well be most useful is a command function for bash: "x-terminal-emulator -use; (opens the terminal, & then next line is simple command syntax) cd filepath/to/directory; file_command; if (consequence), then (next_command), else (typical_command_consequence); exit;"