You can do something as simple as:
command | grep -q 'found' && echo -e '\a'
If the output of command
contains the text "found", then grep
will return with a zero exit status, so the echo
command will be executed, causing the beep.
If the output does not contain "found", grep
will exit with status 1, and will not result in the echo
.
Depending on what you need to make the beep work, just replace anything after the &&
. The general syntax would be something like:
command | grep -q "$SEARCH" && command_if_found || command_if_not_found