How can I tell whether I'm in a screen?

后端 未结 9 1720
悲哀的现实
悲哀的现实 2020-12-07 18:11

When using screen in linux, how can I tell if I\'m in a screen or not? I could do exit and I\'ll exit a screen if I was in one, but if I wasn\'t, then I\'ll end

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 19:03

    While ssh'd into a remote (older) system I noticed that $TERM indicated I was using 'screen-256color', however there was no termcap/terminfo entry for that, so I was forced to resort to the following in .bashrc to prevent the terminal from producing occasional garbage:

    case $TERM in 
        (screen-256color) export TERM='screen'
    esac
    

    to get it to use the plain entry instead.

    TL;DR, $TERM will usually indicate if you are in a screen session when ssh'd remotely. You can use case $TERM in (screen*) echo "you are in a screen session"; esac if you just want a visual clue and don't need to do something specific

提交回复
热议问题