How do I get the command history in a screen session using Bash?

前端 未结 7 1733
悲&欢浪女
悲&欢浪女 2021-02-01 19:08

If I start a screen session with screen -dmS name, how would I access the command history of that screen session with a script?

Using the , the

7条回答
  •  独厮守ぢ
    2021-02-01 19:32

    I put the next lines into my .bashrc:

    case "$TERM" in
       screen)
           declare SCREEN_NAME=$(echo $STY | sed -nr 's/[^.]*\.(.*)/\1/p')
           if [[ $SCREEN_NAME ]]; then
               HISTFILE="${HISTFILE}.${SCREEN_NAME}.${WINDOW}"
               declare -p HISTFILE
           fi
           unset SCREEN_NAME
           ;;
       *)
           ;;
    esac
    

    My default .bashrc has this 'case' basically with 'xterm*|rxvt*)' value, so I only added my 'screen' part into it. If you have not this 'case', you can use the next instead of it:

    if [[ $TERM == screen ]]; then
       declare SCREEN_NAME=$(echo $STY | sed -nr 's/[^.]*\.(.*)/\1/p')
       if [[ $SCREEN_NAME ]]; then
           HISTFILE="${HISTFILE}.${SCREEN_NAME}.${WINDOW}"
           declare -p HISTFILE
       fi
       unset SCREEN_NAME
    fi
    

    And after I have an own bash_history for all window of my all screen.

    Note: this not work in chroot!

提交回复
热议问题