Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for string equality / string comparison in Fish shell?

Tags:

fish

How do you compare two strings in Fish (like "abc" == "def" in other languages)?

So far, I've used a combination of contains (turns out that contains "" $a only returns 0 if $a is the empty string, although that hasn't seemed to work for me in all cases) and switch (with a case "what_i_want_to_match" and a case '*'). Neither of these methods seem particularly... correct, though.

like image 705
Leigh Brenecki Avatar asked Jun 19 '12 21:06

Leigh Brenecki


People also ask

How do you test for equality of strings?

Python strings equality can be checked using == operator or __eq__() function. Python strings are case sensitive, so these equality check methods are also case sensitive.

How do you know if two string variables are equal?

You can check the equality of two Strings in Java using the equals() method. This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

How is string comparison done?

The algorithm to compare two strings is simple: Compare the first character of both strings. If the first character from the first string is greater (or less) than the other string's, then the first string is greater (or less) than the second. We're done.

What is a string comparison?

string= compares two strings and is true if they are the same (corresponding characters are identical) but is false if they are not. The function equal calls string= if applied to two strings. The keyword arguments :start1 and :start2 are the places in the strings to start the comparison.


1 Answers

  if [ "abc" != "def" ]          echo "not equal"   end   not equal    if [ "abc" = "def" ]         echo "equal"   end    if [ "abc" = "abc" ]         echo "equal"   end   equal 

or one liner:

if [ "abc" = "abc" ]; echo "equal"; end equal 
like image 192
Keith Flower Avatar answered Oct 15 '22 03:10

Keith Flower