Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 1
    You can't do that without fifos or temporary files. There are workarounds in some shells, but they're all using extensions. (Notice that this has nothing to do with the child running in the fg/bg, but with the shell not having any way to create anonymous pipes other that via the cmd | cmd syntax). FWIW, exec 1>&4 will not work unless fd 4 is already opened, in which case it will make fd 1 (stdout) an alias of it (dup2(4, 1)). Commented Nov 16, 2019 at 18:30
  • Can you add to your question what (not how) you are trying to do. Commented Nov 16, 2019 at 18:36
  • @ctrl-alt-delor: I added a use case, which may or may not help clarify. Specifically in the simplified example, I want to send data via a numbered file descriptor to a child process. So child should be waiting on a read of fd 4 and I want to pass data to fd 4 in the parent (and have the child read and act on that data). Commented Nov 16, 2019 at 18:52
  • Related: How to make bidirectional pipe between two programs?, How to make a redirection loop, and How do you use the coproc command in various shells? Commented Nov 16, 2019 at 18:57
  • 1
    For the use case from your update: while :; do echo yup; done | your_utility. (yes, that does work; it may be that your_utility is using buffered i/o). As to your "mkfifo or tempfiles without mkfifo or tempfiles", you're free to think I'm talking out of my ass; but if you really have a problem, better explain what you're trying to achieve exactly, maybe there are better ways to do it than the one you have latched onto. Commented Nov 16, 2019 at 20:24