I'm trying to script the spawning of GNU/screen windows by using commands of the form screen <CMD>.

For some reason when I start GNU/screen (by hand), the shell that it starts in window 0 (/bin/bash) does not contain a $STY environment variable. Without this commands like screen vim start a nested screen session, not another window as I want.

My environment is somewhat unusual. Here's how I end up in it:

ssh robm@somehost
sudo su sharedaccount
script /dev/null

The script /dev/null step exists because the TTY device allocated for the robm user cannot be accessed by the sharedaccount user. The script command allocates a new TTY that is owned by the user that invoked it, solving that problem.

If I skip the sudo and script steps, GNU/screen sets $STY just fine. In other words this works just fine:

ssh robm@somehost

Presumably something about sudo and script interferes with screen, but I'm stumped as to what.


Gah, it was the sharedaccount SHELL init script's fault. It was calling exec env -i ... to create a new shell without cruft from the original user's environment.

Sorry if I wasted anyone's time.


I think you could both skip the script /dev/null step and fix your issue if you changed your call to su by issuing it with a dash, like: sudo su - sharedaccount. This would set all your environment variables mostly the way they would be if you'd actually logged in as sharedaccount.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.