鱼壳的条件

han*_*xue 3 shell shell-script fish

我正在浏览鱼壳教程,发现这个简单的 if-else 块不起作用

if grep fish /etc/shells
            echo Found fish
else if grep bash /etc/shells
            echo Found bash
else
            echo Got nothing
end
Run Code Online (Sandbox Code Playgroud)

错误信息:

/usr/bin/fish
Found fish
fish: global root block
fish: Could not locate end of block. The 'end' command is missing, misspelled or
a ';' is missing.

       end - end a block of commands.
Run Code Online (Sandbox Code Playgroud)

rid*_*ish 7

可能您安装了一个非常旧的 (1.x) 版本的 fish,它早于 else-if 构造。什么fish --version输出?理想情况下,您需要 2.1.0。