# Verify that SCREEN_DEFAULT points to an existing SCREEN_XX
if [ -n "$SCREEN_DEFAULT" ]; then
    # We want it to be e.g. 01, not 1
    SCREEN_DEFAULT=$(printf "%02d" "$SCREEN_DEFAULT")
    eval "screen=\$SCREEN_$SCREEN_DEFAULT"
    if [ -z "$screen" ]; then
        echo "SCREEN_DEFAULT=$SCREEN_DEFAULT, but no SCREEN_$SCREEN_DEFAULT found" >&2
        unset SCREEN_DEFAULT
    fi
fi

# Otherwise, the highest screen number gets to be the default
if [ -z "$SCREEN_DEFAULT" ]; then
    for i in 12 11 10 09 08 07 06 05 04 03 02 01; do
        eval "screen=\$SCREEN_$i"
        if [ -n "$screen" ]; then
            SCREEN_DEFAULT="$i"
            break
        fi
    done
fi

if [ -n "$SCREEN_DEFAULT" ]; then
    set_lts_var SCREEN_DEFAULT "$SCREEN_DEFAULT"
fi
