Consider the following command. I want to echo "yes" if grep has output and echo "no" if grep returns no output.
cat myfile | grep "something"
Can I do this without if command?
grep sets its exit code to 0 ("success") if it finds something:
grep something myfile &>/dev/null && echo yes || echo no
cat, what exactly is your problem withif? Or maybe the correct question is "what are you really trying to do?" – geekosaur May 11 '12 at 16:30