0

I was playing with an script that sends text to a tmux stdin after this answer (https://unix.stackexchange.com/a/773049/189571 by @Kamil Maciorowski) and I was wrongly doing this

tty=$(tmux new-session -d -s aux -PF "#{pane_tty}")
echo -n foo > $tty && tput cr > $tty && echo bar > $tty
tmux capture-pane -t aux -p -S0 -E3

which results in foo PROMPT %> bar (undeterministically sequenced, and PROMPT is printed)

whereas the same but using command tail -f /dev/null as an argument of tmux new-session, as Kamil suggested, gives bar as result , which is what I expected

I would like to understand why without tail everything fails. Isn't tail -f /dev/null here sort of an sleep infinity? What's the difference with not passing any command? I mean if you don't pass anything to new-session, the pane is kept alive until kill-session as well

1 Answer 1

2

tmux new-session with a command starts the command in a new tmux pane in a new tmux window in a new tmux session.

tmux new-session without any command starts an interactive shell instead.

In your case PROMPT %> is the prompt this shell prints. I guess your line with echos gets executed immediately, so there is a race condition and the prompt may get to the tty (in the pane) before foo or after bar, or between foo and bar.

tput cr > $$tty did not print to the desired tty because $$ expanded to the PID of the shell parsing the line. Most likely you have created a regular file named 12345tty or so, the output of tput is inside the file.

1
  • sorry, the $$tty part was a typo. But I see what you mean thanks!!!
    – Whimusical
    Commented Mar 25 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .