* [gentoo-user] Can a script tell if it's running under X? @ 2004-12-04 21:34 Kevin O'Gorman 2004-12-04 21:43 ` Nick Rout ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Kevin O'Gorman @ 2004-12-04 21:34 UTC (permalink / raw To: gentoo-user Is there a way for a script (bash, for instance) to know if it's running under X, such as in an xterm or konsole? I want to have scripts that run graphical tools if the infrastructure is present, and text tools otherwise. For me this is particularly useful for tools I don't use all that often, and can forget that a graphical version exists. ++ kevin -- Go back to the top: I almost always top-post Kevin O'Gorman, PhD -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 21:34 [gentoo-user] Can a script tell if it's running under X? Kevin O'Gorman @ 2004-12-04 21:43 ` Nick Rout 2004-12-06 2:07 ` cdemarco 2004-12-04 21:45 ` Matan Peled 2004-12-04 22:54 ` Peter Gordon 2 siblings, 1 reply; 12+ messages in thread From: Nick Rout @ 2004-12-04 21:43 UTC (permalink / raw To: gentoo-user One way is test if $DISPLAY is set, if it is then you are running in X On Sat, 2004-12-04 at 13:34 -0800, Kevin O'Gorman wrote: > Is there a way for a script (bash, for instance) to know > if it's running under X, such as in an xterm or konsole? > > I want to have scripts that run graphical tools if the > infrastructure is present, and text tools otherwise. > For me this is particularly useful for tools I don't use > all that often, and can forget that a graphical version > exists. > > ++ kevin > -- Nick Rout <nick@rout.co.nz> -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 21:43 ` Nick Rout @ 2004-12-06 2:07 ` cdemarco 2004-12-06 4:19 ` Iain Buchanan 0 siblings, 1 reply; 12+ messages in thread From: cdemarco @ 2004-12-06 2:07 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 517 bytes --] On Sun, Dec 05, 2004 at 10:43:05AM +1300, Nick Rout wrote: > One way is test if $DISPLAY is set, if it is then you are running in > X If you login via SSH and have X forwarding enabled, you might not want to burn bandwidth on an X app. The *safest* way IMHO is to set an env var, e.g. "GOT_X='yes'" in your .xsession/.xinitrc! -- % You are in a maze of twisty passages, all alike. Christopher DeMarco <cdemarco@fastmail.fm> PGP public key ID 0x2E76CF5C @ pgp.mit.edu +6012 232 2106 [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-06 2:07 ` cdemarco @ 2004-12-06 4:19 ` Iain Buchanan 0 siblings, 0 replies; 12+ messages in thread From: Iain Buchanan @ 2004-12-06 4:19 UTC (permalink / raw To: gentoo-user On Mon, 2004-12-06 at 10:07 +0800, cdemarco@fastmail.fm wrote: > On Sun, Dec 05, 2004 at 10:43:05AM +1300, Nick Rout wrote: > > > One way is test if $DISPLAY is set, if it is then you are running in > > X > > If you login via SSH and have X forwarding enabled, you might not want > to burn bandwidth on an X app. If you don't want to use X in this case, then you probably won't have $DISPLAY set :) Its a good idea IMHO to stick to conventions - how annoying would it be if each app had its own $DISPLAY like variable that you had to set? You can always add a --nox or -nw or whatever (like emacs etc) if the user wants to override it... HTH, -- Iain Buchanan <iaindb at netspace dot net dot au> You know you're using the computer too much when: u type amd instead of and -- DEaigo -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 21:34 [gentoo-user] Can a script tell if it's running under X? Kevin O'Gorman 2004-12-04 21:43 ` Nick Rout @ 2004-12-04 21:45 ` Matan Peled 2004-12-05 0:55 ` Bastian Balthazar Bux 2004-12-04 22:54 ` Peter Gordon 2 siblings, 1 reply; 12+ messages in thread From: Matan Peled @ 2004-12-04 21:45 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 531 bytes --] Kevin O'Gorman wrote: >Is there a way for a script (bash, for instance) to know >if it's running under X, such as in an xterm or konsole? > >I want to have scripts that run graphical tools if the >infrastructure is present, and text tools otherwise. >For me this is particularly useful for tools I don't use >all that often, and can forget that a graphical version >exists. > >++ kevin > > > Another way would be to check ${TERM} - on a tty, its "linux", and in X it specifies the terminal emulator (rxvt, xterm, Eterm, etc.). [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 21:45 ` Matan Peled @ 2004-12-05 0:55 ` Bastian Balthazar Bux 0 siblings, 0 replies; 12+ messages in thread From: Bastian Balthazar Bux @ 2004-12-05 0:55 UTC (permalink / raw To: gentoo-user Matan Peled wrote: > Kevin O'Gorman wrote: > >> Is there a way for a script (bash, for instance) to know >> if it's running under X, such as in an xterm or konsole? >> >> I want to have scripts that run graphical tools if the >> infrastructure is present, and text tools otherwise. >> For me this is particularly useful for tools I don't use >> all that often, and can forget that a graphical version >> exists. >> >> ++ kevin >> >> >> > Another way would be to check ${TERM} - on a tty, its "linux", and in > X it specifies the terminal emulator (rxvt, xterm, Eterm, etc.). dangerous, if you login via telnet or ssh it's a choiche of the client and thae coise is pretty large -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 21:34 [gentoo-user] Can a script tell if it's running under X? Kevin O'Gorman 2004-12-04 21:43 ` Nick Rout 2004-12-04 21:45 ` Matan Peled @ 2004-12-04 22:54 ` Peter Gordon 2004-12-05 0:22 ` Collins Richey ` (2 more replies) 2 siblings, 3 replies; 12+ messages in thread From: Peter Gordon @ 2004-12-04 22:54 UTC (permalink / raw To: gentoo-user -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Kevin O'Gorman wrote: | Is there a way for a script (bash, for instance) to know | if it's running under X, such as in an xterm or konsole? | | I want to have scripts that run graphical tools if the | infrastructure is present, and text tools otherwise. | For me this is particularly useful for tools I don't use | all that often, and can forget that a graphical version | exists. One way to do it (though I don't know how to do this in Bash) is to check X's Process ID (PID). If `pidof X` returns an integer, than that's the PID of the currently running X server. If X is not running it will return an empty string. /home/peter $ pidof X 12521 /home/peter $ pidof non-running-app /home/peter $ Hope this helps! - -- () The ASCII Ribbon Campaign - against HTML Email, /\ vCards, and proprietary formats. - --------------------------------------------------- Peter A. Gordon (codergeek42) E-Mail: admin@ramshacklestudios.com GPG Public Key ID: 0x109DBECE GPG Key Fingerprint (SHA1): ~ E485 E2F7 11CE F9B2 E3D9 C95D 208F B732 109D BECE Encrypted and/or Signed correspondence preffered. - --------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBskA1II+3MhCdvs4RAjCOAKCzApn5hQ6w0yor2JMp2xASs8BzeQCgkUyp 5Yi1b6GIKNHVR2QYEwIFfEE= =9Wp6 -----END PGP SIGNATURE----- -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 22:54 ` Peter Gordon @ 2004-12-05 0:22 ` Collins Richey 2004-12-05 7:31 ` Peter Gordon 2004-12-05 8:25 ` Uwe Thiem 2004-12-05 8:27 ` Marko Vallius 2 siblings, 1 reply; 12+ messages in thread From: Collins Richey @ 2004-12-05 0:22 UTC (permalink / raw To: gentoo-user On Sat, 04 Dec 2004 14:54:47 -0800, Peter Gordon <admin@ramshacklestudios.com> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Kevin O'Gorman wrote: > | Is there a way for a script (bash, for instance) to know > | if it's running under X, such as in an xterm or konsole? > | > | I want to have scripts that run graphical tools if the > | infrastructure is present, and text tools otherwise. > | For me this is particularly useful for tools I don't use > | all that often, and can forget that a graphical version > | exists. > > One way to do it (though I don't know how to do this in Bash) is to check X's > Process ID (PID). If `pidof X` returns an integer, than that's the PID of the > currently running X server. If X is not running it will return an empty string. > > /home/peter $ pidof X > 12521 > > /home/peter $ pidof non-running-app > > /home/peter $ > > Hope this helps! > For the normal non-root user case, this would be '/sbin/pidof X', unless you have monkeyed with the standard $PATH setup. -- Collins -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-05 0:22 ` Collins Richey @ 2004-12-05 7:31 ` Peter Gordon 2004-12-05 15:08 ` Collins Richey 0 siblings, 1 reply; 12+ messages in thread From: Peter Gordon @ 2004-12-05 7:31 UTC (permalink / raw To: gentoo-user -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Collins Richey wrote: | For the normal non-root user case, this would be '/sbin/pidof X', | unless you have monkeyed with the standard $PATH setup. What do you mean? I have done nothing with my $PATH and let Portage handle it as needed. On my system, /usr/bin/pidof is a symlink to /bin/pidof /home/peter $ ls -al `which pidof` lrwxrwxrwx 1 root root 10 Apr 9 2004 /usr/bin/pidof -> /bin/pidof - -- () The ASCII Ribbon Campaign - against HTML Email, /\ vCards, and proprietary formats. - --------------------------------------------------- Peter A. Gordon (codergeek42) E-Mail: admin@ramshacklestudios.com GPG Public Key ID: 0x109DBECE GPG Key Fingerprint (SHA1): ~ E485 E2F7 11CE F9B2 E3D9 C95D 208F B732 109D BECE Encrypted and/or Signed correspondence preffered. - --------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBsrlWII+3MhCdvs4RAsHKAKDGy4ZUwr/X0902i48eFqnWpLCumQCgxNbB M+kci9q/ljNFYacNLEK90eE= =dnKK -----END PGP SIGNATURE----- -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-05 7:31 ` Peter Gordon @ 2004-12-05 15:08 ` Collins Richey 0 siblings, 0 replies; 12+ messages in thread From: Collins Richey @ 2004-12-05 15:08 UTC (permalink / raw To: gentoo-user On Sat, 04 Dec 2004 23:31:36 -0800, Peter Gordon <admin@ramshacklestudios.com> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Collins Richey wrote: > | For the normal non-root user case, this would be '/sbin/pidof X', > | unless you have monkeyed with the standard $PATH setup. > > What do you mean? I have done nothing with my $PATH and let Portage handle it as > needed. On my system, /usr/bin/pidof is a symlink to /bin/pidof > > /home/peter $ ls -al `which pidof` > lrwxrwxrwx 1 root root 10 Apr 9 2004 /usr/bin/pidof -> /bin/pidof > Sorry for the confusion. I was running from a Fedora Core 3 system to check out what many local users here are experiencing (nothing expecially good, except that xscreensaver runs ok, whereas it fails on my gentoo system). Apparently Red Hat (and some other systems) have /sbin/pidof. 'which pidof' from a normal user finds nothing. -- Collins -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 22:54 ` Peter Gordon 2004-12-05 0:22 ` Collins Richey @ 2004-12-05 8:25 ` Uwe Thiem 2004-12-05 8:27 ` Marko Vallius 2 siblings, 0 replies; 12+ messages in thread From: Uwe Thiem @ 2004-12-05 8:25 UTC (permalink / raw To: gentoo-user On Sunday 05 December 2004 00:54, Peter Gordon wrote: > Kevin O'Gorman wrote: > | Is there a way for a script (bash, for instance) to know > | if it's running under X, such as in an xterm or konsole? > | > | I want to have scripts that run graphical tools if the > | infrastructure is present, and text tools otherwise. > | For me this is particularly useful for tools I don't use > | all that often, and can forget that a graphical version > | exists. > > One way to do it (though I don't know how to do this in Bash) is to check > X's Process ID (PID). If `pidof X` returns an integer, than that's the PID > of the currently running X server. If X is not running it will return an > empty string. The $DISPLAY method is safer. X could be running for another user, or X is running for you but the script isn't running in a login shell, or or or. Uwe -- Alternative phrasing of the First Law of Thermodynamics: If you eat it, and you don't burn it off, you'll sit on it. http://www.uwix.iway.na (last updated: 20.06.2004) -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Can a script tell if it's running under X? 2004-12-04 22:54 ` Peter Gordon 2004-12-05 0:22 ` Collins Richey 2004-12-05 8:25 ` Uwe Thiem @ 2004-12-05 8:27 ` Marko Vallius 2 siblings, 0 replies; 12+ messages in thread From: Marko Vallius @ 2004-12-05 8:27 UTC (permalink / raw To: gentoo-user On Sat, Dec 04, 2004 at 02:54:47PM -0800, Peter Gordon wrote: > Kevin O'Gorman wrote: > | Is there a way for a script (bash, for instance) to know > | if it's running under X, such as in an xterm or konsole? > > One way to do it (though I don't know how to do this in Bash) is to > check X's Process ID (PID). If `pidof X` returns an integer, than > that's the PID of the currently running X server. If X is not running > it will return an empty string. That doesn't really work. `pidof X` does often return the PID of the currently running X server, yes, but it does not tell you if you are running under it (it can be some other user's X, for example). On the other hand, the X server's process name probably is X only if you're running XFree or X.org. What if you're running Xvnc? :) You can also log in remotely and run X applications. Running `pidof X` will then make absolutely no sense, as *your* X server is running on the machine you logged in from... Checking if $DISPLAY is set is the way to go. If it's not set, you cannot start any X apps anyway. (Well, sometimes you can if you know what your display is, but if we knew that we wouldn't be having this conversation.) -- Marko Vallius # PGP public key A4B84F58 -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2004-12-06 4:20 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-12-04 21:34 [gentoo-user] Can a script tell if it's running under X? Kevin O'Gorman 2004-12-04 21:43 ` Nick Rout 2004-12-06 2:07 ` cdemarco 2004-12-06 4:19 ` Iain Buchanan 2004-12-04 21:45 ` Matan Peled 2004-12-05 0:55 ` Bastian Balthazar Bux 2004-12-04 22:54 ` Peter Gordon 2004-12-05 0:22 ` Collins Richey 2004-12-05 7:31 ` Peter Gordon 2004-12-05 15:08 ` Collins Richey 2004-12-05 8:25 ` Uwe Thiem 2004-12-05 8:27 ` Marko Vallius
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox