
다음 명령을 고려하십시오. grep에 출력이 있으면 "yes"를 에코하고 싶습니다. grep이 출력을 반환하지 않으면 "no"를 에코하고 싶습니다.
cat myfile | grep "something"
if
명령 없이도 할 수 있나요 ?
답변1
사용부울 제어 연산자:
[[ -n $(your command) ]] && echo "yes" || echo "no"
답변2
grep
무언가가 발견되면 종료 코드가 0("성공")으로 설정됩니다.
grep something myfile &>/dev/null && echo yes || echo no