In GNU Screen, how can I create a new window whose shell inherits the environment of the shell in the current window?
The usual Ctrl+A C doesn't seem to do this.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
If you've set environment variables on one screen (say running bash), and then open a new screen, it is a separate bash process and therefore will not pick up the environment on the separate already running bash shell. A quick fix to get around the issue would be:
env TERMCAP= env | sed -r 's/^(\w+)=(.*)$/\1="\2"/' > env.sh
then once you've Ctrlac to get a new shell you can then
It's hacky and I use
env TERMCAP= env because the TERMCAP environment variable is multi-line and makes the
sed far more complicated. It's not pretty, but it works :)
You may want to change it to do:
env TERMCAP= env | sed -r 's/^(\w+)=(.*)$/export \1="\2"/' > env.sh
So the variables are also exported.
Exported variables, as shown by
env should automatically be inherited by your new
However, local variables which you have defined in your shell before starting
screen, but which you have not exported, will not exist in the screen session.
Depending on how you name your variables, you could use something like this in Bash to get a readable list :
(set -o posix ; set) | egrep -v '^(_.*|[A-Z0-9_]+)='
set by itself would also list tons of functions.
(set -o posix ; set) will list only variables, but there is a ton of system variables in that list.
egrep -v '^(_.*|[A-Z0-9_]+)=' filters out all variables with a name that starts with an underscore, and all those which have only uppercase letters, numbers and underscores. That should get rid of most system variables.
So the list is restricted to variables which also (or only) use lowercase letters (and underscores and numbers). Now you could copy what you want from that list before starting screen, and paste it in there.
Of course, that is only useful if you have many variables which you forgot to export, but you do remember to check them out before starting screen...