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?
Use boolean control operators:
[[ -n $(your command) ]] && echo "yes" || echo "no"
grep sets its exit code to 0 ("success") if it finds something:
grep something myfile &>/dev/null && echo yes || echo no
grep -q then you don't need &>/dev/null.
cat, what exactly is your problem withif? Or maybe the correct question is "what are you really trying to do?"