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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communitygrep
sets its exit code to 0 ("success") if it finds something:
grep something myfile &>/dev/null && echo yes || echo no
Use boolean control operators:
[[ -n $(your command) ]] && echo "yes" || echo "no"
cat
, what exactly is your problem withif
? Or maybe the correct question is "what are you really trying to do?"