GNU Screen: How can I create a screen in the background if it doesn't exist? GNU Screen: How can I create a screen in the background if it doesn't exist? shell shell

GNU Screen: How can I create a screen in the background if it doesn't exist?


I believe you're looking for the -d -R combination:

screen -d -R -S test

From man screen:

      -d -R   Reattach a session and if necessary detach or  even  create  it              first

EDIT

If you just want to create a background screen only if it doesn't exist, a little shell function in your ~/.bashrc or ~/.zshrc will work:

function bgsc {   if screen -list | awk '{print $1}' | grep -q "$1$"; then    echo "screen $1 already exists" > &2  else    screen -d -m -S $1  fi}

Then just call bgsc test.