Check if screen

I have a shell script. I need to make sure when a user executes it, it will be run on a screen in the shell.

If the user starts a screen first and runs the screen, the script should continue running.

If the user did not start a screen and attempted to run the script, the script should automatically start a screen and run continue with the other commands in the script.

Is this possible?

Well, X support usually comes with $DISPLAY. Do you really care if it is a screen, if the called app can make a screen?

$ xterm -e touch /tmp/X-OK.$$

GNU screen, right? You can check $STY to see if you're inside of a screen session, I think.

If not, you would start a new process, "exec screen myscript" I suppose. ?

edit: like this?

#!/bin/sh
 
# Go no further unless we're in a screen session!
[ "$STY" ] || exec screen $0
echo you are ok
sleep 3600

I keep forgetting about screens, since modems got past 14400 and IP RAS PPP overtook telnet dialup and slip/slurp. :smiley: