[OT] how can a bash script determine if it's running in an xterm???

Steven W. Orr steveo at syslang.net
Wed Jul 7 16:57:53 UTC 2004


On Wednesday, Jul 7th 2004 at 12:51 -0400, quoth Joe(theWordy)Philbrook:

=>-----BEGIN PGP SIGNED MESSAGE-----
=>Hash: SHA1
=>
=>
=>Actually there are three states I want to base some conditional execution
=>on. 
=>
=>I can do this now based on feeding the script a command-line argument.
=>But I'm wanting to have the script itself determine if:
=>
=>1) It's running in a VT such as found in runlevel 3 or via ctrl+alt+F1
=>   in runlevel 5.
=>
=>2) It's running in an "xterm", "konsole", "aterm", or (ANY other x based
=>   terminal window).
=>
=>3) It's not attached to a terminal or VT (such as might happen if the
=>   script was called from alt+F2 run prompt).
=>
=>How can a bash script test it's environment for these three different
=>conditions???
=>
=>Please! and Thank you!

1. Check out the tty command and the runlevel command.

2. Look at the TERM environment variable.

	if [[ "$TERM" = xterm ]]
	...

3. If the PS1 environment variable is null then you were not called 
interactively. e.g.
	if [[ -z "$PS1" ]]
	then
	    echo 'I am not interactive'
	else
	    echo 'I am interactive.'
	fi

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net





More information about the fedora-list mailing list