2 Likes
If you really do not want to get rid of the pipe for whatever reason, the following way also yields the same result in Bash.
printf '%s\n' "$(<bar.txt)" | grep foo
If you do not necessarily need the pipe, but you need to pass the file’s content to a command’s standard input, then you may use a here string.
grep foo <<<"$(<bar.txt)"
Using the above alternatives is pretty much always better than using cat
.
Use cat
only, if you actually need it. Like for example, for concatenating file contents.
1 Like