Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe to executable without exiting/EOF in bash

Tags:

bash

sh

I have a (read-only) executable "myexec" which I always execute followed by the input "input1" (a string), and then I get on with my business "" and "exit" when I feel like it:

$ myexec
> input1
> do something else for as long as I like
> exit

What I would like to do is automatically execute "myexec" with the input "input1", and then be able to "do something else for as long as I like". From what I can see, my options are:

$ myexec <<< "input1"

or

$ echo "input1" | myexec

or

$ myexec << EOF
input1
EOF

BUT the problem with these methods is that they terminate "myexec" after reading "input1". How can I avoid the EOF/exit/terminate?

like image 376
kd88 Avatar asked Mar 25 '13 14:03

kd88


People also ask

How do you stop EOF?

The best practice to avoid EOF in python while coding on any platform is to catch the exception, and we don't need to perform any action so, we just pass the exception using the keyword “pass” in the “except” block.

What is << EOF in bash?

This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended. Similarly, in bash, the EOF operator is used to specify the end of the file.

How do you echo EOF?

Save this answer. Show activity on this post. There is no way to echo out an EOF. An EOF can only be generated either by reaching the end of a file or by invoking the keypress bound to the eof terminal setting ( Ctrl D by default) when the file being read is bound to the terminal.

How do you send EOF to pipe?

You cannot “send EOF”. There is simply no “EOF character” that would go through the pipe. Typically, linux programs read from a file descriptor using read (2) in blocking mode, filling a buffer with the received data, and returning the amount of characters read.


1 Answers

You can use cat for this:

$ { echo "input1"; cat; } | my exec
like image 120
chepner Avatar answered Oct 06 '22 09:10

chepner