4 ms·
Can someone give a few prominent examples of fundamental differences from bash? I don't mean trivial things like having `config.fish` instead of `.bashrc`, or
by einpoklum 7y ago
Can someone give a few prominent examples of fundamental differences from bash? I don't mean trivial things like having `config.fish` instead of `.bashrc`, or not using fi and esac to conclude if and case statements.
I noticed fish has:
* extensive syntax highlighting
* "global" variables shared by all instances of fish, persisting past reboots.
what are other important features?
- atemerev 7y agoGood and well-thought shell language syntax (compared to ad-hoc hodgepodge of syntactic peculiarities of bash/zsh); reasonable defaults for the interactive shell. No other shell gives you this, for some reason.
- hnlmorg 7y ago> No other shell gives you this, for some reason. That's not true. There are a few other shells out there that do. The issue is the popular shells tend to be the ones that go for POSIX (or Bash) compatibility and those that do go for a syntax redesign (for example) often get criticised for not being POSIX compatible. There is comment further down in this discussion describing those syntax differences as "bugs" rather than "features"; which just goes to demonstrate how ingrained Bash et al are to Linux/UNIX command line users. Personally I see Fish and other non-POSIX shells like another programming language (arguably that's literally what they are). So switching from Bash to Fish - or whatever else - should be like switching from C++ to C#, Java, Rust, whatever. Sure there will be a lot of commonalities but it is the differences what makes the shift worthwhile. That all said, I can't blame people for preferring a POSIX or Bash compatible shell because that's what you'd expect to find on any Linux or UNIX system. Or at the very least a Bourne Shell (sh). Plus most documentation online will be tailored for compliant shells. However it does become a self-fulling prophecy where compliant shells are more widely used because they're already more widely used. I'm fine with this though. People who want to make the shift and learn something new can still do so under the knowledge that they're breaking from the norms and all the potential complications that might bring; and people who just want something that's universal and works - irrespective of it's warts - can continue to do so.
- atemerev 7y agoYes, you are right. I believe that we software engineers should not dwell in such conservative states of mind and innovate and even break from standards when necessary. Bash and POSIX were good enough 30 years ago when they first appeared. Now they feel really dated.
- yoloClin 7y agoI would _kill_ for a shell that returns bash-like data to stdout, but a JSON blob to pipes, or whatever the not-1970 concept of a pipe would be.
- umanwizard 7y agoThe shell isn’t in charge of what data commands print out.
- yoloClin 7y agoTrue, but it's driven the method for output for a long time. If sh/bash exposed functions for objective output I'm sure a lot more utilities commonly in use would output in a similar methodology.
- umanwizard 7y agoNo it hasn’t. The shell isn’t involved at all in program output. When a program writes to stdout it’s talking directly to the kernel, and the shell is suspended and not running.
- yoloClin 7y agoI don't really care what outputs the data I see. I care about how it's formatted and whether that format is easily readable + usable by consuming utilities. I don't understand why your being standoffish over a technicality.
- einpoklum 7y agoCan you give a couple of examples (and I mean - things I might actually type in an interactive shell)?
- duckerude 7y agoAs much as possible, syntax looks like shell commands, and blocks uniformly end with `end`. You don't get the messy inconsistency of sh where functions use braces and conditionals use ALGOL-style `fi` and `esac` and loops use `done`. Beyond that, some control structures even support flags: if you want to read up on function definition you can run `function --help`, and if you want to define a function `foo` that completes like `git` you define it with `function foo --wraps=git; ...; end`. That means you have to keep less in your head. A lot of things are even defined as ordinary fish functions. In sh, aliases are a dark and evil feature that hooks into the parser and can be used to create rudimentary macros. They have some really surprising behavior. But in fish, `alias` is a shell function and you can get the complete source code on your screen by running `type alias`. It doesn't do any evil things because it can only do things you could do yourself. Fish has sensible variables and arrays. All variables can be arrays. When unquoted, variables expand like "$@" in sh, so packing multiple arguments inside a variable is trivial and there's no need to worry about whitespace. Command output splits on newlines, which means that things like `for file in (find . -iname 'foo')` just work, assuming you don't have newlines in your filenames. Writing one-liners in fish makes me much less anxious then doing so in sh.
- deleted 7y ago[deleted]
- Quequau 7y agoFor me the killer feature is that for me, as a casual user, it's easier to be productive. There are just so many weird little things that folks do in shells that I don't do often enough for me to remember exactly how to do them. Though I'll say up front, again as a casual user, I'm not sure exactly how fish accomplishes making me more productive than bash. I'm also don't know if I ought to switch to something like zsh. I often read folks saying great things about zsh but it seems more like something aimed at "power users" and that ain't me.
- yoloClin 7y agooh-my-zsh has 'sane' defaults (and by that I mean 4-8 hours of configuration at least). I'm in the process of moving from that to self-managed zsh and I'm surprised with the stuff that doesn't come default with ZSH, such as not setting the <title> of the shell to $(pwd) or the currently executing process, or control codes.
- maverwa 7y agoComes out of the box with a lot of useful auto completes, highlighting etc. Can do most of this with zsh and a lot of scripts/config but in fish it „just works“. Except you have to learn a new language. () for $(), „; and“ instead of „&&“ etc.
- saila 7y ago&& and || are supported in the latest version of fish (I think starting with 3.0).
- e12e 7y agoMany great responses here. I've considered switching from bash to fish (something I never did with zsh). The main reason I didn't is Stockholm syndrome, or that I'm too used to bash by now. I think you can get zsh to do most of what fish does out of the box. If bash is Ed, it feels zsh is emacs and fish is (neo)vim. Zsh is huge and I always get a bit of a panic attack when someone has given me a ssh login with zsh as the default shell. And an irrational urge to maul a unicorn. With fish, it feels more like a friend went and tidied up your apartment just to be nice. I guess I'm so used to bash, that the limited support that comes from completions is enough - and I end up writing a bit of documentation and automation, and work on "foreign" (other people's) servers - and it helps me to work in a posix shell for that reason - with fewer surprises. You might even find that fish does out of the box something bash (now) can too - just isn't enabled by default or in typical distribution's configs. Ymmv - it's worth testing imnho. And more interesting than zsh, which just feels like someone was bored in it class in high school and added colors and tinkered with the prompt, and tried à million different ideas - but never really liked working in shell.
- AnthonBerg 7y agoMaybe I did it wrong, but I tried zsh and used some common packages and things to get it to work like Fish. zsh became super slow.
- yjftsjthsd-h 7y ago>If bash is Ed, it feels zsh is emacs and fish is (neo)vim. I would have thought fish=emacs and zsh=vim in this analogy, since fish isn't really compatible with bash but zsh is?
- e12e 7y agoI was more thinking of how many(?) people will readily use a only slightly customized vim - and be reasonable productive in a standard config, vs emacs where the stronger trend seems to be building an ide on top of emacs - to the point were to users can't readily use each other's setup efficiently - or indeed use the standard distribution without customization.
- ufo 7y agoA big one is that unquoted variable expansion does not split on whitespace. This avoids all sorts of spaces-in-filenames bugs. For a similar reason, command substitution only splits on newlines. Unfortunately, some commands like pkg-config assume that the shell splits on regular spaces so you will need to use workarounds like (pkg-config | string split "")