Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This a deeper explanation for the question.

My goal is:

  1. Start a bash shell configured with a set of environment variables, but running in the background.

  2. Launch about five screen commands in the bash shell, each executing its own commands, but using the environment variables set in the bash shell. The screen commands should all be arranged in the bash window, preferably tiled.

  3. Call up the bash shell later, with the all the screen commands showing.

  4. Close the bash shell and the associated screen when done.

share|improve this question

migrated from Dec 29 '12 at 9:32

This question came from our site for professional and enthusiast programmers.

@KingSkippus There are quite a few good bash and screen related answers here, so I will give it sometime. – vfclists Dec 29 '12 at 4:16
up vote 3 down vote accepted

Well, after some time on your question there is some observations:

line 2: commands should all be arranged in the bash window, preferably tiled is not possible, as when detached, there is no windows.

So when you re-attach, you will always see only one pseudo-tty.

But to do approximatively what asked for, try the following:

First create a RCfile as typing: cat >screenRcTest whith the following:

setenv MyVariable Test
screen -t Top top
screen -t VMStat vmstat -n 1
screen -t OpenPorts watch -n 2 'netstat -tan | grep LISTEN'
screen -t IF-Configs watch -n2 'ip -s link show | grep -v "^ *[RT]X: bytes"'
screen -t "Bourne Again Shell" /bin/bash -i

Than prepare a run wrapper as:

screen -ls | grep -q screenTest || screen -dmS screenTest -c ./screenRcTest

this will run a new screen session in background if not already exist.

For building tiled presentation, prepare another shell script as cat >screenSplitTest


while read line ;do
    screen -X $line
done <<eof
resize 20
split -v
resize 82
select 0
select 1
split -v
select 2
select 3
select 4

and don't forget chmod +x screenSplitTest.

Finally run the display command as:

xterm -fn 9x15 -geom 160x60 -exec screen -DrS screenTest 

This will open a new window with only a bash ready.

In this inner bash, hit simply:


This will split your window and let you ready again, in your bash session.

result screenshoot

Type now:

echo $MyVariable

So you will see how Environment variable as passed to child bash.

Edit addition:

After doing all, you could hit the following in your inner bash:

trap '[ $(tput lines) == 60 ] && [ $(tput cols) == 160 ] && ./screenSplitTest' WINCH

So you could disconnect by typing: Ctrl-A d than next time you run xterm whith same arguments and geometry, the script screenSplitTest will be initiated automatically.

Edit 2

And now, you could even install this trap in your .bashrc, using MyVariable for ensuring that bash is a child of screenRcTest screen (after moving screenSplitTest to a hidden file in $HOME/.screenSplitTest for constance):

[ "$TERM.$MyVariable" == "screen.Test" ] && \
    trap '[ $(tput lines) == 60 ] && [ $(tput cols) == 160 ] && $HOME/.screenSplitTest' WINCH
share|improve this answer
@FHauri All I can say is is Wow! I see you just joined superuser. Where were you in the past when we needed you? :) – vfclists Dec 30 '12 at 15:59
Thank! I've added a little .bashrc line to make them more automatic. – F. Hauri Dec 30 '12 at 16:31

To my knowledge you cannot tile screen instances, but you can tile tmux instances. What you could do is to create an rc-file for the shared environment settings, and then load this to each of your 5 bash shells using bash --rcfile <your file here>.

The bash shells would be started by launching tmux, and when inside, execute some command to create a new split (for instance Ctrl+b % for a vertical split, using standard settings) for each bash instance.

share|improve this answer
tmux was another utility I had in mind but I have no experience with it but I know it will be useful one day. – vfclists Dec 30 '12 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .