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