Send Keys to a tmux Pane from a Script
Type into a pane from a script with tmux send-keys -t name 'command' Enter. Words like Enter are key names, and -l sends the text as typed instead.
A script should start a command in a tmux session and push input to it without attaching.
tmux new -d -x 80 -y 24 -s demo "env PS1='$ ' bash --norc"
tmux send-keys -t demo 'echo hi' Enter
tmux send-keys -t demo -l 'Enter'
sleep 0.3
tmux capture-pane -p -t demo | head -4
tmux kill-server$ echo hi
hi
$ EnterEach argument after the target is either text, which is typed as it is, or the name of a key such as Enter, C-c or Up. The name of a key is only recognized as a whole argument, so 'echo hi' Enter types the text and then presses return. With -l everything is literal, and the word Enter is typed as five letters, as the last line of output shows. The key names are listed in the tmux manual.
send-keys is asynchronous. It returns when the keys are queued, not when the command has finished, so a script that reads the pane next needs a short wait or a marker to poll for. Typing into a pane that runs a program other than a shell sends keys to that program. For a one-shot command, tmux new -d 'command' is simpler.