Bash · Techniques
Loop over lines
while read hands each line to decide on its own. The loop acts on each answer.
The two complaints open a case. The thanks and the question about blue do not.
question="Is this a complaint?"
is_complaint() {
printf '%s' "$1" |
thinkthen decide "$question" --quiet
}
cat <<'EOF' |
Arrived a day early. Thank you!
The zipper broke the first time I used it.
Does this come in blue?
The strap snapped on day two.
EOF
while read -r review; do
if is_complaint "$review"; then
echo "Open a case: $review"
fi
doneOutput
Open a case: The zipper broke the first time I used it. Open a case: The strap snapped on day two.
exit 0
On GitHub: github.com/botassembly/thinkthen