Will writing to /dev/pts allow me to source ~/.bashrc?
4
votes
1
answer
270
views
I have several terminal windows already open; I just made a change to
~/.bashrc
, and I'd like to run source ~/.bashrc
in each of the open terminals.
It seems to me that if I just
source ~/.bashrc | tee /dev/pts/{0..12}
, then ~/.bashrc
should be run in each terminal. It looks like it was, since I include a clear
at the end of ~/.bashrc
.
However, what I'm specifically testing is whether
PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}"
actually creates a single source of truth for all my terminals, and was modified in each open terminal.
Now I'm not sure if this has something to do with writing to /dev/pts/{0..12}
or is related to the way that history
functions. If I look at one of my open terminals which is running git log
, and echo $PROMPT_COMMAND
, I do **NOT** see the modifications I would expect had ~/.bashrc
been sourced. As a consequence of the history
commands missing, I do not see git log
output in a separate terminal, running tail -f ~/.bash_history
, which I would expect to see if PROMPT_COMMAND
was indeed modified after source ~/.bashrc
.
However, if I ask each terminal echo $PROMPT_COMMAND | tee /dev/pts/{0..12}
, what the value of PROMPT_COMMAND
is, I get:
history -a; history -c; history -r; pre_prompt_command; echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"
which includes history -a; history -c; history -r;
, the changes that I added in ~/.bashrc
.
Now I'm confused. What am I doing wrong? Or what do I not understand correctly? Was PROMPT_COMMAND
modified or was it not? Or is this a consequence of how bash / linux works? I'm pretty sure it's user error, and not a bug.
Asked by Radoslav Ivanov
(41 rep)
Apr 14, 2024, 02:46 PM
Last activity: Apr 28, 2024, 12:50 PM
Last activity: Apr 28, 2024, 12:50 PM