Why & How fish does not support POSIX?
fish isn't and never tried to be compatible with POSIX sh.
This really just means that it's a separate language (like Java, Python or Ruby) rather than an implementation or extension of sh (like Bash, Dash and Ksh).
Obviously, just like you can't copy-paste Java snippets into a Python program, you can't copy-paste sh
code into fish
.
In practice, this means that when you search for things like "how do I show the current git branch in my prompt", you need to make sure you find fish
answers because the sh
ones won't work. Similarly, when books or instructions give commands to run, you may occasionally need to rewrite some of them manually (or open a bash
shell and paste them there).
Whether this matters is entirely up to you, so definitely give it a go.
Actually, fish
is not compliant with the POSIX sh
definition. But neither is csh
(and probably zsh
). You still can use fish
as your interactive shell.
For example echo $$
shows the pid of the shell in POSIX sh
. But with fish
it does not.
(and that is why I did not switch to fish
and keep using zsh
as my daily interactive login shell)
You could change your interactive login shell (using chsh
) to fish
.
But if you write shell scripts, writing them for the POSIX sh
specification make these scripts more portable. (You'll use the shebang #!/bin/sh
to start them, it is understood by Linux execve(2)). In some cases, you don't care about portability of your shell script and you could make them start with #!/usr/bin/fish
to be fish
scripts. Then they won't work on systems without fish
.
Also, the system(3) C standard library function uses /bin/sh -c
.
I enjoyed very much Yann Regis-Gianas' talk on POSIX [s]hell at FOSDEM2018.