Search code examples
fish

Testing command substitution output in fish


There is another question about testing command substitution for a particular string. I want to test if a command outputs anything in a single statement, i.e., the equivalent of:

if [[ -n "$(foo)" ]]

in bash. Fish doesn't recognize [[]], and

if [ -n "(foo)" ]  # No good, "(foo)" is literal.
if [ -n (foo) ] # Passes only if (foo) == "\n" because of test semantics.

Won't work meaning I have to

set check (foo)
if [ -n "$check ]

Is there a possibility I've missed here?


Solution

  • This should work:

    if count (foo) > /dev/null