if grep -q SomeString "$File"; then
Some Actions # SomeString was found
fi
grep
의 -q
옵션: 화면에 표시하지 않겠다.포함되어 있지 않은걸 확인하려면 간단히 맨 앞에 !
(not) 만 붙여주면 된다.
if ! grep -q SomeString "$File"; then
Some Actions # SomeString was not found
fi
./somecommand | grep 'string' &> /dev/null
if [ $? == 0 ]; then
echo "matched"
fi
또는
if ./somecommand | grep -q 'string'; then
echo "matched"
fi
string='My long string'
if [[ $string == *"My long"* ]]; then
echo "It's there!"
fi