Is it possible in a script to tell if it is being run from within GNU screen?

There is an environment variable for that. If it is being run within screen, $TERM will be screen. It's that simple; just do an if on it. For instance,

if [ $TERM != 'screen' ]; then echo foo; else echo bar; fi

will echo bar when in screen; foo otherwise.


While you're working with screen, why not run the script with 'nohup'? This will also ensure that it continues to run if you get disconnected.

It outputs to a file by default, so you can use other tools to monitor script output if you wish.