Ubuntu – Alternative for |(pipe) operator

bash

I'm looking for a alternative for | operator in bash shell for redirecting output of command as input to the next command. Is there any alternative?

something like :

command1 | command2 | command3

with alternative to:

command1 X command2 X command3

X will be use in place of |. Is it possible to avoid of using | and replace it with the actual operator of that?

Best Answer

The equivalent of command1 | command2 is command2 < <(command1)

This can be extended to three (or more) commands too.

command3 < <(command2 < <(command1))

$ lspci | grep 'Network'
 02:00.0 Network controller: Qualcomm Atheros AR9285 Wireless Network Adapter (PCI-Express) (rev 01)

$ grep 'Network' <(lspci)
 02:00.0 Network controller: Qualcomm Atheros AR9285 Wireless Network Adapter (PCI-Express) (rev 01)

$ lspci | grep 'Network' | grep -o 'controller'
 controller

$ grep -o 'controller' < <(grep 'Network' < <(lspci))
 controller

However, as Oli suggested, although this may produce the same output, it isn't technically the same as a pipe.

<(..) turns the internal command output's STDOUT into a file handler (that the command, grep in your example) opens. When you pipe, the reading command is reading directly from STDIN (which is being filled with the piped command's STDOUT). Subtle differences but can be significant with commands that only know how to read STDIN.