在 fish shell 中结合 if 条件与 contains 函数

Combine if conditions with contains function in fish shell

我似乎无法将多个 if 条件与 contains 函数结合起来,请参阅此示例:

> function if_test
      if contains "h" $argv; or contains "-h" $argv
          functions if_test
          return
      end
  end
> if_test h
# ... works fine.
> if_test -h
# ... shows documentation of contains

这很奇怪,因为以下函数按预期工作,那么为什么会有所不同?

> if true; and false
     echo what
  else
    echo how
  end
how

> if true; or false
     echo what
  else
    echo how
  end
what

-h 被解释为 contains 的选项 - --help 的缩写形式,因此它打印 contains 帮助。使用 -- 表示选项结束:

if contains h -- $argv; or contains -- -h $argv

请注意,此处的引号只是安慰剂 - "h" 完全等同于 h。如果没有任何特殊字符(如空格),引号不会改变任何内容。