When I run a grep
pipeline directly I get two lines of output:
$ grep Interface /proc/net/bonding/bond0 | cut -d : -f 2 | sed 's/ //g'
eno1np0
eno2np1
$
Strangely, the output is empty when I capture it and call echo
:
$ echo $(grep Interface /proc/net/bonding/bond0 | cut -d : -f 2 | sed 's/ //g')
$
A for
loop through grep's output shows many empty lines:
$ for a in $(grep Interface /proc/net/bonding/bond0 | cut -d : -f 2 | sed 's/ //g'); do echo $a; done
$
For what it's worth, I have tried redirecting stderr to stdout with no luck:
echo $(grep Interface /proc/net/bonding/bond0 2>&1 | cut -d : -f 2 | sed 's/ //g')
I even tried using cat
instead of grep
.
How can I get echo
to actually print what's being output by the grep
command? Normally, echo
works. I can echo output just I like normally would, for other things. I can echo text into a file. I just can't get it to work with this grep
pipeline.