* [gentoo-user] Test for X from cli
@ 2006-08-01 19:20 John J. Foster
2006-08-01 19:37 ` dg
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: John J. Foster @ 2006-08-01 19:20 UTC (permalink / raw
To: Gentoo User
[-- Attachment #1: Type: text/plain, Size: 252 bytes --]
Good afternoon,
In a bash script, how can I test whether the script itself is being
run from a virtual terminal, or from an emulator like konsole within X?
Thanks,
festus
--
Ambition is a poor excuse for not having enough sense to be lazy.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
@ 2006-08-01 19:37 ` dg
2006-08-01 23:13 ` John J. Foster
2006-08-01 19:41 ` Uwe Thiem
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: dg @ 2006-08-01 19:37 UTC (permalink / raw
To: Gentoo User
On Tuesday 01 August 2006 23:20, John J. Foster wrote:
> Good afternoon,
>
> In a bash script, how can I test whether the script itself is being
> run from a virtual terminal, or from an emulator like konsole within X?
>
> Thanks,
> festus
Hi,
One possible solution would be to check the value of $TERM variable... If it
is 'xterm' then you're probably in the X terminal emulator.
BR,
dmitri
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
2006-08-01 19:37 ` dg
@ 2006-08-01 19:41 ` Uwe Thiem
2006-08-01 20:27 ` Rick van Hattem
2006-08-01 19:43 ` Philip Webb
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Uwe Thiem @ 2006-08-01 19:41 UTC (permalink / raw
To: Gentoo User
On 01 August 2006 20:20, John J. Foster wrote:
> Good afternoon,
>
> In a bash script, how can I test whether the script itself is being
> run from a virtual terminal, or from an emulator like konsole within X?
See this script by the name "strangename":
#! /bin/sh
ps ax | grep strangename
If run in a terminal under X it will output something like:#
20516 pts/3 R+ 0:00 grep strangename
Please note the "pts".
Run from a virtual text terminal, that will be something like "tty4".
Instead of actually displaying the output, you can analyse it within your
script.
Uwe
--
Mark Twain: I rather decline two drinks than a German adjective.
http://www.SysEx.com.na
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
2006-08-01 19:37 ` dg
2006-08-01 19:41 ` Uwe Thiem
@ 2006-08-01 19:43 ` Philip Webb
2006-08-01 22:09 ` John J. Foster
2006-08-01 19:59 ` Alex Schuster
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Philip Webb @ 2006-08-01 19:43 UTC (permalink / raw
To: gentoo-user
060801 John J. Foster wrote:
> In a bash script, how can I test whether the script itself is being run
> from a virtual terminal, or from an emulator like konsole within X?
'echo $DISPLAY' returns ':0' from Konsole,
but nothing from a raw terminal called up via Ctl-Alt-F2 .
--
========================,,============================================
SUPPORT ___________//___, Philip Webb : purslow@chass.utoronto.ca
ELECTRIC /] [] [] [] [] []| Centre for Urban & Community Studies
TRANSIT `-O----------O---' University of Toronto
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
` (2 preceding siblings ...)
2006-08-01 19:43 ` Philip Webb
@ 2006-08-01 19:59 ` Alex Schuster
2006-08-01 20:45 ` Jesús Guerrero
2006-08-02 4:23 ` Daniel Iliev
5 siblings, 0 replies; 11+ messages in thread
From: Alex Schuster @ 2006-08-01 19:59 UTC (permalink / raw
To: gentoo-user
John writes:
> In a bash script, how can I test whether the script itself is being
> run from a virtual terminal, or from an emulator like konsole within X?
You can check the existance of the DISPLAY environment variable:
if [[ $DISPLAY ]]
then
echo "We're running under X"
else
echo "No X running."
fi
Alex
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:41 ` Uwe Thiem
@ 2006-08-01 20:27 ` Rick van Hattem
0 siblings, 0 replies; 11+ messages in thread
From: Rick van Hattem @ 2006-08-01 20:27 UTC (permalink / raw
To: gentoo-user; +Cc: Uwe Thiem
[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]
On Tuesday 01 August 2006 21:41, Uwe Thiem wrote:
> On 01 August 2006 20:20, John J. Foster wrote:
> > Good afternoon,
> >
> > In a bash script, how can I test whether the script itself is being
> > run from a virtual terminal, or from an emulator like konsole within X?
>
> See this script by the name "strangename":
>
> #! /bin/sh
>
> ps ax | grep strangename
>
>
> If run in a terminal under X it will output something like:#
> 20516 pts/3 R+ 0:00 grep strangename
>
> Please note the "pts".
>
> Run from a virtual text terminal, that will be something like "tty4".
>
> Instead of actually displaying the output, you can analyse it within your
> script.
>
> Uwe
>
> --
> Mark Twain: I rather decline two drinks than a German adjective.
> http://www.SysEx.com.na
I'd look at the TTY variable instead of using ps :)
And as Philip said, to see wheter it is being run from X (with screen you also
have a pts instead of a tty) you can usually use the DISPLAY variable.
--
Rick van Hattem Rick.van.Hattem(at)Fawo.nl
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
` (3 preceding siblings ...)
2006-08-01 19:59 ` Alex Schuster
@ 2006-08-01 20:45 ` Jesús Guerrero
2006-08-02 4:23 ` Daniel Iliev
5 siblings, 0 replies; 11+ messages in thread
From: Jesús Guerrero @ 2006-08-01 20:45 UTC (permalink / raw
To: Gentoo User
El Martes, 1 de Agosto de 2006 21:20, John J. Foster escribió:
> Good afternoon,
>
> In a bash script, how can I test whether the script itself is being
> run from a virtual terminal, or from an emulator like konsole within X?
>
> Thanks,
> festus
If you need more concrete info, $TERM is also your friend.
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:43 ` Philip Webb
@ 2006-08-01 22:09 ` John J. Foster
2006-08-02 3:25 ` Donnie Berkholz
0 siblings, 1 reply; 11+ messages in thread
From: John J. Foster @ 2006-08-01 22:09 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 530 bytes --]
On Tue, Aug 01, 2006 at 03:43:12PM -0400, Philip Webb wrote:
> 060801 John J. Foster wrote:
> > In a bash script, how can I test whether the script itself is being run
> > from a virtual terminal, or from an emulator like konsole within X?
>
> 'echo $DISPLAY' returns ':0' from Konsole,
> but nothing from a raw terminal called up via Ctl-Alt-F2 .
>
Of the different methods suggested, I like this one best.
Thanks to all who replied,
festus
--
Ambition is a poor excuse for not having enough sense to be lazy.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:37 ` dg
@ 2006-08-01 23:13 ` John J. Foster
0 siblings, 0 replies; 11+ messages in thread
From: John J. Foster @ 2006-08-01 23:13 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 361 bytes --]
On Tue, Aug 01, 2006 at 11:37:17PM +0400, dg wrote:
> On Tuesday 01 August 2006 23:20, John J. Foster wrote:
>
> One possible solution would be to check the value of $TERM variable... If it
> is 'xterm' then you're probably in the X terminal emulator.
"probably" is not good ;-)
--
Ambition is a poor excuse for not having enough sense to be lazy.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 22:09 ` John J. Foster
@ 2006-08-02 3:25 ` Donnie Berkholz
0 siblings, 0 replies; 11+ messages in thread
From: Donnie Berkholz @ 2006-08-02 3:25 UTC (permalink / raw
To: gentoo-user
John J. Foster wrote:
> On Tue, Aug 01, 2006 at 03:43:12PM -0400, Philip Webb wrote:
>> 060801 John J. Foster wrote:
>>> In a bash script, how can I test whether the script itself is being run
>>> from a virtual terminal, or from an emulator like konsole within X?
>> 'echo $DISPLAY' returns ':0' from Konsole,
>> but nothing from a raw terminal called up via Ctl-Alt-F2 .
>>
> Of the different methods suggested, I like this one best.
This will also be set in ssh sessions with X forwarding turned on. You
might want to check whether you're in one of those as well.
Thanks,
Donnie
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-user] Test for X from cli
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
` (4 preceding siblings ...)
2006-08-01 20:45 ` Jesús Guerrero
@ 2006-08-02 4:23 ` Daniel Iliev
5 siblings, 0 replies; 11+ messages in thread
From: Daniel Iliev @ 2006-08-02 4:23 UTC (permalink / raw
To: gentoo-user
John J. Foster wrote:
> Good afternoon,
>
> In a bash script, how can I test whether the script itself is being
> run from a virtual terminal, or from an emulator like konsole within X?
>
> Thanks,
> festus
Hello,
Here is yet another approach.
So I would use the command "tty".
========
danny@localhost ~ $ whatis tty
tty (1) - print the file name of the terminal connected to standard input
========
So the check could look something like this:
#!/bin/sh
for ttyX in /dev/tty*;
do
[ "`tty`" == "$ttyX" ] && { echo "no X" ; break ; }
echo "X section"
done
--
Best regards,
Daniel
--
gentoo-user@gentoo.org mailing list
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-08-02 4:27 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-01 19:20 [gentoo-user] Test for X from cli John J. Foster
2006-08-01 19:37 ` dg
2006-08-01 23:13 ` John J. Foster
2006-08-01 19:41 ` Uwe Thiem
2006-08-01 20:27 ` Rick van Hattem
2006-08-01 19:43 ` Philip Webb
2006-08-01 22:09 ` John J. Foster
2006-08-02 3:25 ` Donnie Berkholz
2006-08-01 19:59 ` Alex Schuster
2006-08-01 20:45 ` Jesús Guerrero
2006-08-02 4:23 ` Daniel Iliev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox