I use multiple screens on my system, I'm using separate session for each branch I may be working on. Now I would like to set environment variables depending on screen name (I name screens by branch path). I've tried this in ~/.screenrc:

screen -t "ABC-1234" bash -ic 'OUTPUTROOT=/home/me/src/NextGen/branches/ABC-1234/bin'
screen -t "ABC-1234" bash -ic 'SVN_ROOT=/home/me/src/NextGen/branches/ABC-1234'
screen -t "DEF-5678" bash -ic 'OUTPUTROOT=/home/me/src/NextGen/branches/DEF-5678/bin'
screen -t "DEF-5678" bash -ic 'SVN_ROOT=/home/me/src/NextGen/branches/DEF-5678'

but it doesn't seem to work, the env variables do not get set if my screens are called "ABC-1234" or "DEF-5678" and I open a new window using Ctrl-a c ...


Just start your screens from a shellscript:

SVN_ROOT=/home/me/src/NextGen/branches/ABC-1234 OUTPUTROOT=$SVN_ROOT/bin screen -dm -t "ABC-1234"
SVN_ROOT=/home/me/src/NextGen/branches/DEF-5678 OUTPUTROOT=$SVN_ROOT/bin screen -dm -t "DEF-5678" 
  • but this will create 4 screen sessions which is not what I want/need. I need two sessions with both, OUTPUTROOT & SVN_ROOT set. – stdcerr Oct 24 '17 at 13:06
  • i unfortunately am not able to get it to work the way I want, that's why I've asked the question! I've tried multiple things including: OUTPUTROOT=/home/me/src/NextGen/branches/$1/bin;SVN_ROOT=/home/me/src/NextGen/branches/$1 screen -dm -S $1; but this does not seem to set OUTPUTROOT at all but only SVN_ROOT - $1 being the string I pass to my bash script with the name of the branch/screen session – stdcerr Oct 24 '17 at 13:43
  • so, then... [updated answer] – Ipor Sircer Oct 24 '17 at 13:46
  • 1
    ; always separates two commands, but you were asked for one screen per line. If you wanna use one command, then don't separate them with ;. – Ipor Sircer Oct 24 '17 at 13:47

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.