2
votes

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?

3

3 Answers

4
votes

This should work:

if count (foo) > /dev/null
1
votes

As far as I know there is no way to use string substitution in Fish.

You can follow #159 issue to get more info about current solutions.

1
votes

In fish, we have to use test instead [ or [[

if test -n (foo)
  echo not empty
end

Or, the equivalent of the bash [[ -n $(foo) ]] && echo not empty is

test -n (foo); and echo not empty