The .screenrc file allows the user to specify that they want multiple windows open when screen is first run. Eg.

screen -t myWindowA 0 "" 
screen -t myWindowB 1 "-${SHELL}" 
screen -t myWindowC 2 "-${SHELL}"

What I would like is for each window to run some commands first, like:

screen -t myWindowA 0 "<go to directory a, source a.sh" 
screen -t myWindowB 1 "-${SHELL} <go to directory b, source b.sh>" 
screen -t myWindowC 2 "-${SHELL} <go to directoy c; start a watch on `ls -l`>"

Is there any way to do that?

Note this is similar to, but different from this issue.


Sure you can. On my servers i have a /etc/screenrc with:

screen -t TOP 0 top
screen -t ETC 1 cd /etc
screen -t Console 2
  • the first example works great, but I can't seem to get it to work with sourced environments, eg "source env.sh". I get "Cannot exec 'source': No such file or directory" then "[screen is terminating]". When I try to "cd" as in your second example, I get the a similar error. – Robert Gowland Nov 8 '10 at 19:58
  • 1
    @Robert Gowland source is a bash builtin, so it can't be executed by scree... Your best option, IMHO, is to create some bash scripts and execute them instead. – Mr Shunz Nov 9 '10 at 10:37
  • cool. Thanks for helping me understand what will and won't work. – Robert Gowland Nov 9 '10 at 14:13

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.