I'm sometimes logged in on a host which I do not control and where
readonly. Is there some way to work around this to run
history commands anyway, for example using
PS1? I've tried
PS1='$(history -a; history -c; history -r; echo finished)' - It prints
finished at each prompt, but it doesn't seem to work:
- Open two terminals A and B on the same host.
- In terminal A, run a command
- In terminal B, run a command
- It terminal B, press ↑ twice.
On a host where
PROMPT_COMMAND='history -a; history -c; history -r;', this will result in terminal B showing
a. On a host where
PS1 starts with
$(history -a; history -c; history -r; echo finished) it will instead show whichever command was run before both terminals were opened. The obvious reason is that the command in
PS1 is run in a subshell.
Another alternative is to bypass the global RC-file altogether:
bash --rcfile ~/.bashrc
However, circumventing the use of the standard value of
PROMPT_COMMAND will very likely not be accepted by the sysadmin for policy reasons.