I have this bash script:
#!/bin/bash
external_output="Oliver's AirPort Express"
if ~/.bin/audiodevice | grep "$external_output"
then
~/.bin/audiodevice output "Internal Speakers"
echo "Internal Speakers"
else
~/.bin/audiodevice output "$external_output"
echo "Oliver's AirPort Express"
fi
If the grep is matched, then it of course echoes the match. As I am using it in an if statement, I don’t want this to echo.
How can I use grep in my if statement without having it announce the result to me when I run the script?
You want
grep -q "$external_output"to suppress the output. Fromman grep: