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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/23/2010 2:38 PM, Germán A. Racca wrote:
> On Tue, 2010-02-23 at 20:23 +0000, James Wilkinson wrote:
>
>> Germán A. Racca wrote:
>>
>>> How to know if I'm using an xterm or a gnome-terminal from command line?
>>>
>>> The output of "echo $TERM" is "xterm" from both of them.
>>>
>>> How to know?
>>>
> 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).
>
> Germán.
>
What about something like this in your script?

     PARENTPID=$(ps -o ppid -p $PPID | tail -n1)
     ps u -p $PARENTPID | grep xterm && { echo "Yes!"; } || { echo "no"; }

The first line gets the parent of your script's parent process (so 
bash's parent). Then the second line prints out the information based on 
that pid, which is what you're testing against.

If there are more levels in between, this doesn't work the way it is, 
but you should be able to easily scale it to a loop which keeps going 
either until it hits an xterm process or hits init (as a last resort. 
Maybe there are better conditions you could figure out).

Justin Willmert
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux