kawing-chiu
kawing-chiu

Reputation: 2695

(Script)How to start gnu screen interactively and then run some command in it?

What I want to achieve is as the following:

  1. Start from bash in some terminal
  2. Run gnu screen: exec screen
  3. Start my desktop session in background: startx &
  4. So now I end up with a terminal with screen running and X running in backgroud(in some vt) ready to use and connect from elsewhere through screen.

But I want to automate the above procedure in a script(in fact to put it in my ~/.bashrc). What's the simple and elegant way to do it?

The closest shot I got is like this:

exec screen bash -c "startx; bash"

but this way startx cannot get into background. That is,

exec screen bash -c "startx &; bash"

won't work.

Also, I ran into this thread when googling. But

exec screen bash -i << EOF
startx &
exec < /dev/tty
EOF

don't work either. I also tried

exec screen bash -i --rcfile /tmp/somefile

with startx & in /tmp/somefile. Again not working.

Any ideas?

Upvotes: 0

Views: 699

Answers (1)

chepner
chepner

Reputation: 530960

Both & and ; are command terminators; you can only use one or the other.

exec screen bash -c "startx & bash"

Upvotes: 1

Related Questions