Reputation: 767
I am trying to programmatically fetch history from a bash terminal from within a child process (go executable). I'm essentially looking for the last N commands the terminal has run.
Flow:
The bash built-in history
does not yield proper results when run under go/shell out.
Reading ~/.bash_history
is not accurate as the history from a bash terminal is written when the prompt is closed.
Wondering if this is possible at all?
Upvotes: 0
Views: 293
Reputation: 755
As suggested here you can save the new commands to a file with history -a <file_path>
, then in the child process you can read the last N lines from the file (with tail -n <N>
).
Upvotes: 1