How does 'screen' impact environment variables?
A process inherits the environment variables from the parent, this means the first time you call screen
(create a new one) it has a copy of all the environment variables of the parent process. Now screen
adjusts/creates some variables like COLUMNS
, LINES
, TERM
, TERMCAP
, WINDOW
and STY
. You can also adjust or delete environment variables in your screenrc
with setenv
/unsetenv
.
On some systems, screen
is setuid or setgid in order to update utmp
and wtmp
; then a few more variables are removed from the environment when screen
starts, such as LD_LIBRARY_PATH
.
If you attach to an existing screen
session your environment variables won't be copied as the screen
process already exists and has it own environment variables (from the time when you started the process before). This means your changed environment variables won't be visible in the processes started by screen as they are copied from the parent process which has the old environment variables.
Related videos on Youtube
Kevin Lee
If it isn't on the internet, it may not actually exist. I believe that sites like Stack Overflow do a wonderful service in filling in knowledge gaps for programming. What good is a result if it's not meant to be shared?
Updated on September 18, 2022Comments
-
Kevin Lee over 1 year
I noticed a difference in 'env' before and after a 'screen' call, is there any additional clarity on what gets called (for setting environment variables)?
I couldn't see any clear explanation from a quick search on 'man screen'
Some googled queries on the topic:
http://alan.lamielle.net/2009/03/09/environment-variables-and-gnu-screen
I guess a more specific sub-question would be, what is not instantiated in a screen session vs. that of a normal log-in?