Issue
I've got a Bash script which is only ever going to be invoked via a pipe. I'm curious what's the best way to read the data from the pipe? The command will look like:
$ output_gen | process
My script is process. This is not homework, but it is a learning exercise.
Solution
When your program is receiving data from a pipeline, it's received via stdin. To read from stdin, use the read
builtin. Here is an example:
myprog:
while read -r line; do
<something with "$line">
done
command:
printf 'foo\nbar\n' | ./myprog
Answered By - jordanm Answer Checked By - Timothy Miller (WPSolving Admin)