Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
tmux start script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
SarahS93
l33t
l33t


Joined: 21 Nov 2013
Posts: 677

PostPosted: Thu Nov 17, 2022 8:26 am    Post subject: tmux start script Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 20747

PostPosted: Thu Nov 17, 2022 4:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
SarahS93
l33t
l33t


Joined: 21 Nov 2013
Posts: 677

PostPosted: Mon Nov 21, 2022 6:57 am    Post subject: Reply with quote

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
View user's profile Send private message
user
Apprentice
Apprentice


Joined: 08 Feb 2004
Posts: 191

PostPosted: Mon Nov 21, 2022 12:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 20747

PostPosted: Mon Nov 21, 2022 3:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
user
Apprentice
Apprentice


Joined: 08 Feb 2004
Posts: 191

PostPosted: Mon Nov 21, 2022 3:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 20747

PostPosted: Mon Nov 21, 2022 3:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum