I have a shell script which ends with a few pipes
grep ... | while read ...| sort | uniq and I want to return 1 if the output is empty, but uniq always returns 0 even if its input is empty.
So far the best solution I've found is adding grep with an empty pattern
... uniq | grep '', this works perfectly but feels more like a hack.
So my question is: Is there any better/canonical way to do this?
- I don't want to capture my output in a variable since I would need to print it again afterwards:
a=$(... | uniq); printf '%s\n' "$a"; [ -n "$a" ]which doesn't feel right either.
- If possible I'd also prefer a standard tool (no moreutils) and something portable