I just realized that history
does not output anything in a subshell. I'll try to show by counting lines - first a sanity check with echo:
$ echo a | wc -l
1
... and in a subshell:
bash -c 'echo a' | wc -l
1
Indeed, we expect one line output in both cases. Now, for history
:
$ history | wc -l
681
... but in a subshell:
$ bash -c 'history' | wc -l
0
... history
returns no lines.
Why does this happen - and how can I get the history
in the subshell to output the history of the current shell (including last session commands)?