Rems19 Rems19 - 4 years ago 188
Bash Question

How to use exact session name to enter a screen?

I'm using screen to run a lot of different instances of an application and I name the the sessions "app1", "app2" etc.

The problem is that if I have a screen named "app10" started after the one named "app1", when I type

screen -r app1

I get attached to the app10 screen because it's the last screen created "matching" the name app1.

Is it possible to get rid of name matching and use exact names ?

For technical reasons I don't want to change app1 to app01. It's used in directory name, automation etc.

Answer Source

As you rightly pointed out, screen uses the parameter value as a prefix.

A long alternative would be to type:

  screen -r $(basename /var/run/screen/S-$USER/*.app1}

(presuming that your sockets are in the /var/run/screen directory which is the default on Debian systems)

You can create an equivalent bash function in your .bashrc file

   function mscreen() {
      screen -r $(basename /var/run/screen/S-$USER/*$1)

which let you type

 mscreen app1

to recover your session app1 and not app10

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download