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

前端 未结 7 1736
悲&欢浪女
悲&欢浪女 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:36

    @technosaurus is right. $HISTFILE is written when bash exits, so you could exit one bash session, and start a new one, and the history should have been preserved through the file.

    But I think there is a better way to solve your problem. The bash manual includes a description of the history built-in command. It allows you to save this history with history -w [filename] and read the history with history -r [filename]. If you don't provide a filename, it will use $HISTFILE.

    So I would propose that you save the history inside your screen session to a specific file (or to your default $HISTFILE if you want). Then read the history file in the other bash session you want to access the history from. This way you don't have to exit the original bash session.

提交回复
热议问题