I'm curious about whether it's possible to redirect the output of one command directly into the input of another using just redirection operators in Bash. For example, I was wondering about the following syntax:
```bash
cmd1 &<1 # and I want to include a cmd2 that feeds the output to cmd1
```
Normally, this kind of operation is done with pipes (like using `|`), but I'm interested in whether there's a way to achieve it just with redirection syntax. The context for my question stems from my experience using `rm -I`, which prompts for confirmation. While I can already accomplish this with commands like `yes | rm -r folder_name` or using here strings, I'm more interested in the specific redirection aspect. For my exploration, I'd like to find a way to replace the placeholder in my example with something that allows this type of output-to-input redirection. Any insights would be appreciated!
5 Answers
It sounds like you want to make command chaining work differently. Unfortunately, direct output-to-input redirection isn't achievable without using a form of piping or a similar mechanism. But it's great that you're experimenting with shell scripting!
You could try using:
```
cmd1 < <(cmd2)
```
This allows for cmd2's output to be used as input for cmd1 while still maintaining separate processes. It's another way to achieve output-redirection functionality without explicitly using pipes in the traditional sense.
Also, don’t forget about `xargs`! It lets you take the output of one command and use it as arguments for another. While it’s not pure redirection, it might help you achieve your goal depending on how you want to structure your commands.
It sounds like you might be running into an XY problem here. Are you trying to simply automate confirmations for the `rm` command? If so, using `yes | rm` is the classic solution. But if you really want to focus on the redirection aspect, you might want to look into `mkfifo` for named pipes.
What you’re describing is generally what pipes are used for. I understand you're looking for redirection specifically, but keep in mind that pipes are the standard way to send the output of one command to the input of another. If you’re just curious about redirection, though, I don’t think there’s a direct way to achieve exactly what you’re asking without using pipes. However, if you’re open to alternatives like process substitution (`<(command)`), that could be an option for you.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically