How about testing each line of the command output?
#!/bin/bash while read -r line; do echo "$line" if [[ "$line" == "TEST" ]]; then exit fi done < <(cat testfile)
The above reads the output from a given command (in this case "cat testfile"), then echos the result. It checks for a line that equals "TEST" and exits if it finds a match.