Fish shell: if with array

nabbisen

nabbisen

Posted on July 10, 2020

Fish shell: if with array

With fish shell, there are two ways to check if some value exists in array. One is to define array and then use it in if statement, and the other is define array directly in if.

  1. Define array and then use it in if statement

    • Define array: set -l $ARRAY_NAME VALUE1 VALUE2 ....
    • Use it in if statement: if contains $TARGET $ARRAY_NAME

    For example:

    set -l myarray 'member001' 'member002'
    if contains 'member001' $myarray
        #do something
    end
    
  2. Define array directly in if statement
    Curly brackets do the work.

    For example:

    if contains 'member001' {'member001' 'member002'}
        #do something
    end
    
💖 💪 🙅 🚩
nabbisen
nabbisen

Posted on July 10, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Fish shell: if with array
fish Fish shell: if with array

July 10, 2020