Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why & How fish does not support POSIX?

Tags:

shell

posix

fish

I have heard about fish that it's a friendly and out-of-box shell but also it doesn't support POSIX standard. On the other hand I read about POSIX standard (and also I tested it on my Fedora, It's amazing and out-of-box shell now I want to change my default shell to fish).

But the matter that I opened this question for is: I misunderstood about relation between fish and POSIX standard, what do you mean about fish does NOT support POSIX exactly? & How? (Should I change my bash to fish?).

Please explain it simple 'cause I'm a little newbie, thanks.

like image 796
Cy8099 Avatar asked Feb 11 '18 15:02

Cy8099


People also ask

Why in the dictionary?

1 : the cause, reason, or purpose for which know why you did it that is why you did it. 2 : for which : on account of which know the reason why you did it. why. noun.

What is that song?

To identify songs, open Control Center, then tap the Shazam button . Shazam can identify songs playing on your device even when you're using headphones. To find songs you've identified, touch and hold the Shazam button in Control Center to open your History View.


Video Answer


2 Answers

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.

like image 113
that other guy Avatar answered Sep 26 '22 15:09

that other guy


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.

like image 30
Basile Starynkevitch Avatar answered Sep 22 '22 15:09

Basile Starynkevitch