Bash Script – How to Make a Bash Script Enter a Certain Keystroke

bashshell-scripttmux

Is there any way to make a bash script enter a certain keystroke? What I'm trying to accomplish here is a script that will run Ctrl+B to exit tmux.

EDIT: I see that several people are saying that it's better to use a program – specific command. What if I wanted to edit a text file (in this case the bash_aliases file) using a bash script?

Best Answer

If you want to interact with tmux in a script, that's where you want to use tmux ... tmux-command. Like:

tmux kill-session

To exit the current session.

tmux kill-server

To exit the server (kills all sessions).

tmux detach-client

to detach a client (exit, but you can reattach later).

Related Question