0

I have a named-pipe:

> ls -l
total 0
prw-r--r--  1 ivan  staff  0 Aug 24 08:32 fifo

In one terminal, I read from it in an infinite loop:

> while true; do sh -c "$(cat fifo)"; done
█

In another, I write runnable commands to the pipe:

> echo 'rspec path/to/example_spec.rb' > fifo

My first terminal runs the command:

> while true; do sh -c "$(cat fifo)"; done
.........

Finished in 0.00194 seconds (files took 0.10327 seconds to load)
9 examples, 0 failures

█

Now I'd like to send a control sequence to change the cursor shape from to _. In the second terminal, I run:

> printf '\e[4 q' > fifo

But the reading terminal reports a garbled error (note the missing "c" in "command"):

sh: ommand not found

I tried \e, \033, ^[, and x1B but all to no avail. I also tried using echo, but I'm on OSX, and BSD echo has no -e option.

How can I send the control-sequence properly escaped?

  • 2
    You're sending a control character, but you're executing it as a command. – Kusalananda Aug 24 '16 at 13:06
  • @Kusalananda Aha! Good point. The purpose of the fifo was to execute commands in the reading terminal. As an afterthought, I wanted to also change the cursor shape. Is that not possible in this scenario? – ivan Aug 24 '16 at 13:10
  • 4
    Since you're wrapping in sh -c you need to send the printf command itself to the fifo so something like echo "printf '\e[4 q'" > fifo – Stephen Harris Aug 24 '16 at 13:14
1

The sh is redundant if you intended to send only escape sequences and text via the fifo. You could do just this:

while true; do cat fifo; done
  • The problem is I mostly want to be able to send runnable commands through the fifo. I was trying to send control sequences in addition to this. – ivan Aug 25 '16 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.