I have a command-line program which takes input from stdin. What's the best way for me to pass a line of stdin into that program using bash? I have two approaches which accomplish the job, but they both seem a bit clunky.
I'll illustrate my approaches using a dumbed-down example of counting three words.
using a here doc:
wc -w <<EOS
one two three
EOS
using echo:
echo 'one two three' | wc -w
As I said, both of these seem a bit clunky. Is there a cleaner way to accomplish this?
wc -w <<<"one two three"
is a shorter way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With