## cls
echo ; echo ;echo ; echo ;echo ; echo ;echo ; echo ;echo ; echo ;

export SESSION="An Example"
export SESSION_FIND="\\.$SESSION.("

## We want exactly one line
## If hh != tt, then there is more than one line
export hh=`screen -list | grep "$SESSION_FIND" | head -n1`
export tt=`screen -list | grep "$SESSION_FIND" | tail -n1`
if [ "$tt" = "$hh" ]; then
  ## Note that when using exact, we cannot simply use `screen -xRR $SESSION` since the matching used by scren is not the same as we are using with grep
  if [ ! -z "$hh" ]; then
    export SESSION_USING="$(grep -oP "([0-9]+\.[aA-zZ]*)" <<< "$hh")"
    echo "Resuming SESSION_USING=$SESSION_USING"
    screen -xRR "$SESSION_USING"
  else
    echo "Starting new SESSION=$SESSION"
    screen -S "$SESSION"
  fi
else
  echo ""; echo ""; echo " MORE THAN ONE MATCH";  echo ""; echo "";
  # This will fail but will show options
  screen -r $SESSION
fi
