4

I am working on my fish.config for using the fish shell.

I am trying to compare strings using bash syntax but fish doesn't accept the syntax. There is clearly another way to do it. Any suggestions for a solution as clean as the bash solution below?

if [[ $STRING == *"other_string"* ]]; then
    echo "It contains the string!"
fi

1 Answer 1

10

It looks to me like there's a string function for that purpose:

$ set STRING something here
$ string match -q "other_string" $STRING; and echo yes
$ set STRING some other_string here
$ string match -q "other_string" $STRING; and echo yes
yes

Or:

if string match -q "other_string" $STRING
  echo it matches
else
  echo is does not match
end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .