8

I'm trying to run a series of commands in tmux from a remote file like so:

tmux $(wget -qO- http://example.com/tmux)

The file contains commands like split-window and send-keys

The problem is, send-keys is stripping spaces. The send-keys commands is:

send-keys ssh example.com C-m;

But instead it sends sshexample.com

Any idea why?

Cheers!

Andrei Serdeliuc
  • 895
  • 4
  • 14
  • 26

4 Answers4

2

As a guess, it's interpreting "send-keys ssh example.com C-m;" as four separate arguments and not knowing what to put between them.

Try:

tmux "$(wget -qO- http://example.com/tmux)"
wfaulk
  • 6,828
  • 7
  • 45
  • 75
1

It is not that send-keys is "stripping spaces" exactly, but that Space is one of the special keys recognized by tmux and expected to be used with the send-keys command.

So, rather than

send-keys ssh example.com C-m;

in this case, you would use

send-keys ssh Space example.com C-m;

More on this can be found on tmux send-keys syntax

ljs.dev
  • 1,174
  • 2
  • 8
  • 15
0

It's doing that because the <Space> key is considered a special character. To fix the issue, you need to escape the character by using the \ key.

Let's say we want to send the command ipython --no-autoindent to the terminal. If we did it like this:

tmux send-keys 'ipython --no-autoindent

The output sent would be: $ ipython--no-autoindent

==================================

This is how to send it with escaping the space:

tmux send-keys 'ipython \ --no-autoindent'

And if you try it, your output would be: $ ipython --no-autoindent

-1

I've struggled a bit with similar issue. The solution turned out to be:

tmux send-keys -l $var;
tmux send-keys C-m;

thanks to -l, tmux paid attention to all the signs. On the downside, it didn't accept <enter> so separated call is required.