Howto start and detach screen with user environment on startup?
I think your problem here is the session-handling of bash. Bash - like any other shell interpreter - detects if it is started in the backgroud, or if it is attached to a terminal ( Interactive / Non-interactive mode ). Background is found here.
My guess is, that your problems are solved by providing the -l
switch to the first bash command:
screen -dmS scr bash --login -c 'ytop; exec bash'
The --login
switch makes bash read all startup files, like /etc/profile
, ~/.bash_profile
, ~/.bash_login
, and ~/.profile
- which should contain the environmental variables you are missing.