I'm trying to get only the last command ran in a different Bash window. I have the other Bash window's PID. I can run
APID=<bash pid number>; gdb -batch --eval "attach $APID" --eval "call write_history(\"/tmp/bash_history-$APID.txt\")" --eval 'detach' --eval 'q'
but it writes that to a file.
What would be an sh
command that would output the last line of the result of that function call without creating a temporary file?
tail -1 ~/.bash_history
.bash_history
is usually only written when the shell exits so a simpletail
probably won't work.gdb
to tell Bash to write the history, which is contained in memory, of a currently running shell. In fact, I just tested it, and that's what it does. Andtail -n 1 ~/.bash_history
doesn't show the most recent command from the test session.