how to know if I'm using xterm or gnome-terminal?

birger birger at birger.sh
Tue Feb 23 22:44:11 UTC 2010


On Tue, 2010-02-23 at 19:07 -0300, Germán A. Racca wrote:
> On Tue, 2010-02-23 at 17:06 -0500, Jake Peavy wrote: 
> > On Tue, Feb 23, 2010 at 3:38 PM, Germán A. Racca
> > <german.racca at gmail.com> wrote:
> >         I'm running a program called IRAF to work with astronomical
> >         images, and
> >         it needs to use the graphic capabilities of an xterm, not
> >         gnome-terminal. So, I'm trying to make a very simple script to
> >         start
> >         IRAF, but first I have to know if I'm on an xterm (so it
> >         enters directly
> >         to IRAF) or a gnome-terminal (in this case the script must
> >         open an xterm
> >         before). 

ppid=`grep "^PPid:" /proc/$$/status | sed -e "s/^PPid:[\t ]*//"`
name=`grep "^Name:" /proc/$ppid/status | sed -e "s/^Name:[\t ]*//"`

echo $name

Of course there are still potential errors. The parent of the shell may
not be the terminal. You could check, and if the parent is xterm run in
the terminal. if it is anything else, start it in a new xterm. You will
then get a new xterm if people are logged in remotely or escaping out
from some other app. Perhaps you can live with that?

birger




More information about the users mailing list