View previous topic :: View next topic |
Author |
Message |
SarahS93 l33t

Joined: 21 Nov 2013 Posts: 677
|
Posted: Thu Nov 17, 2022 8:26 am Post subject: tmux start script |
|
|
with
tmux send-keys -t main:2 'echo hello...' Enter
i can send to a running tmux session "main" in window "2"
"hello"
but how can i send something like this:
test -t /tmp/file | grep -Ev "(23|BC|xyZ)"
? |
|
Back to top |
|
 |
Hu Moderator

Joined: 06 Mar 2007 Posts: 20747
|
Posted: Thu Nov 17, 2022 4:08 pm Post subject: |
|
|
Your own example should work for that. You need the sent text to be free of special characters. If you single-quote the argument to the tmux command, that should suffice. What did you try that should have worked? How did it fail? |
|
Back to top |
|
 |
SarahS93 l33t

Joined: 21 Nov 2013 Posts: 677
|
Posted: Mon Nov 21, 2022 6:57 am Post subject: |
|
|
i have tried
tmux send-keys -t main:2 'echo test -t /tmp/file | grep -Ev "(23|BC|xyZ)"' Enter
in the tmux window 2 i see:
sarah@pc1 ~ $ echo test -t /tmp/file | grep -Ev "(23|BC|xyZ)"
test -t /tmp/file
sarah@pc1 ~ $
i will in the tmux window 2 see
test -t /tmp/file | grep -Ev "(23|BC|xyZ)"
only see, not run as command ...
is there a way?! |
|
Back to top |
|
 |
user Apprentice

Joined: 08 Feb 2004 Posts: 191
|
Posted: Mon Nov 21, 2022 12:55 pm Post subject: |
|
|
SarahS93 wrote: | i have tried
tmux send-keys -t main:2 'echo test -t /tmp/file | grep -Ev "(23|BC|xyZ)"' Enter
in the tmux window 2 i see:
sarah@pc1 ~ $ echo test -t /tmp/file | grep -Ev "(23|BC|xyZ)"
test -t /tmp/file
sarah@pc1 ~ $
i will in the tmux window 2 see
test -t /tmp/file | grep -Ev "(23|BC|xyZ)"
only see, not run as command ...
is there a way?! |
It works as expected. Your command was executed.
Have a cross-check and reduce your complexity of your example
Quote: | # tmux send-keys -t main:2 'id | grep uid' enter |
you will see a line because uid string was found by grep
Quote: | # tmux send-keys -t main:2 'id | grep -v uid' enter |
you will see no line, because grep expects lines without uid string (depends on your shell prompt config, RC will indicated) |
|
Back to top |
|
 |
Hu Moderator

Joined: 06 Mar 2007 Posts: 20747
|
Posted: Mon Nov 21, 2022 3:06 pm Post subject: |
|
|
tmux send-keys does not automatically generate a carriage return. If you do not include one in the text to send, then none is generated, and you will need to press Enter in the target window explicitly.
Note that this example is weird: test -t takes the number of a file and tells whether it is a descriptor for a tty. Giving it a filename is ill-formed, produces no output, and exits failure. Code: | $ test -t /
$ echo $?
1
$ test -t 0 </
$ echo $?
1
$ test -t 0 </dev/tty
$ echo $?
0 | In none of those cases does test produce any output on its own. |
|
Back to top |
|
 |
user Apprentice

Joined: 08 Feb 2004 Posts: 191
|
Posted: Mon Nov 21, 2022 3:11 pm Post subject: |
|
|
Hu wrote: | tmux send-keys does not automatically generate a carriage return. If you do not include one in the text to send, then none is generated, and you will need to press Enter in the target window explicitly.
...
|
tmux send-keys ... enter
"enter" is a codeword/option here and will execute command |
|
Back to top |
|
 |
Hu Moderator

Joined: 06 Mar 2007 Posts: 20747
|
Posted: Mon Nov 21, 2022 3:59 pm Post subject: |
|
|
True. It could also just be that the OP is trying to say that a carriage return is typed in the source shell at this point. This is why I always use bold on the text in my posts that is meant to be executed, to make clear what is typed and what is explanatory.
I always found it more convenient to include the carriage return literally in the sent text: tmux send-keys 'echo abc
'. The single quotes allow the carriage return to be part of the argument passed to tmux. |
|
Back to top |
|
 |
|