Bash vs ZSH vs Fish: What's the Difference?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right today we're going to learn about bash zsh and fish and what are the differences between all these different shells now a lot of people are confused about this i was for a long time i wasn't sure what all the different differences there are between all these so in this video i hope to kind of sort things out give you the pros and cons of each of these different shells why you would want to use each of these and then i'll get my recommendations as to what you should use but basically i just want to give you enough facts to give you an informed decision so that you can decide for yourself which of these shells that you want to use on a daily basis and of course let's just start with bash so bash to this date is still the default shell on most machines so most linux distributions and most linux servers that you're going to log on to maybe you're going to ssh into a server it's probably going to be using bash as the default shell so if you have some sort of job where you're doing devops or anything where you're just logging into a whole bunch of different machines via ssh or something like that you're probably going to need to be pretty comfortable with bash because while bash has less features than something like z shell or fish you're not always going to be able to install these different shells on different machines that you log into so if that does describe you if you are going to be ssh into a lot of different things then you are going to want to get pretty familiar with bash even if you want to use something else day to day and before i jump into something like zsh next i'm going to talk about a whole bunch of different features that zsh has so a lot of features like that you see in zsh let me just pull it zsh here maybe you would have as you can see autocomplete right here or syntax highlighting so it's highlighting this screen for me it's highlighting some command i don't have with red and so maybe 10 years ago you couldn't get any of these features in bash but bash has come a long way and now if you want there are projects where you can install where you can get all of these and very similar features into bash as well just because i know if i say that zsh has some feature that bash doesn't then a bunch of bash purists are going to come in here and tell me that actually this feature is available in bash 2. you just need to install this but i will preface that with saying that using something like zsh is much more configurable and much more extensible and it's much easier to add on to than something like bash so just as an example if you want to add something like syntax highlighting or auto suggestions like i showed you then with zsh you can just add that functionality you can just extend the default functionality that's already there but if you want to do something like that in bash then you'd have to install this which is basically a replacement for the default bash line editor so whereas you can customize zsh's line editor that is basically this line right here that you type things into so with zsh you can just add on to it and extend it but with bash you just have to completely replace it just because there's no way to do something like that with just the default gnu readline which it has by default but enough about bash let's actually talk about zsh next so i have zsh right here and zsh is actually pretty similar to bash it just has more features and like i said more customizability so it's easier to add on to and it also has a nice plug-in ecosystem so if you want to add some feature then you would just add some plug-in it can be as simple as just adding a file and sourcing that in your configuration file or you can even install some plug-in manager if you want to and just have it manage all your plugins for you so adding features to zsh is a lot easier than something like bash and i already showed you a few nice features i had like i have this auto complete right here and i have this nice terminal prompt right here it'll give me get information if i'm in a git repository for example but do keep in mind that none of this is available by default so by default you're actually going to get a prompt very similar to bash just like i showed you it's going to have no frills no fancy colors like this so don't assume that you're getting something beautiful like this right out of the box if you do want something like this you are going to have to configure it so let me just open up my zshrc right here and as you can see i have a whole bunch of different lines in here i'm adding in a bunch of options here i'm adding a bunch of plugins down here and a whole bunch of other things i'm sourcing the prompt right here and this was basically all manually done so if you do want a nice usable zsh experience then you are going to have to customize it pretty much as much as you would with bash but just keep in mind that it is a bit easier as you can see to add these plugins here and while you can use some scripts to kind of set everything up for you a lot of people use oh my zsh which sets a lot of this up for you installs a bunch of plugins by default for you you can also use this script that i recommend called zsh for humans which is basically a nice installer for zsh that sets up a whole bunch of plugins and things for you i have a video on that if you want to check that out but i still recommend going through and setting up all the configuration yourself just so you have complete control over your zsh and you know what's going on but if you're the kind of person who doesn't want to go through a whole bunch of configuration in order to set everything up and get it usable then you might not actually want to use zsh so that brings us to our final subject that's going to be fish so let me close this out and open up fish right here clear this and as you can see right here by default we have actually a nice little terminal prompt and we have a whole bunch of features that you might find in zsh but without all the configuration so as you can see i get nice syntax highlighting and auto complete by default as well as a whole bunch of nice other features so you can go in here and go back and then you can type something in like cd and search through your history with up and down right here so i'm scrolling back to when i cd into my config directory so that's useful to find some previous commands if you hit tab you can actually scroll through all these with the arrow keys so the tab completion by default is very nice as well and fish just has a whole bunch of nice sensible default options so fish by default just has a very nice default configuration i did not have to do anything to get all the nice features like i did with zsh this all came out of the box so you just install this and this is what you get and bash and zsh are both very old they've been around for more than 30 years so fish is much more modern and so it makes sense that it would have a much more sensible default configuration basically fish just works if you want something that you just take out of the box and everything just works fine then you might want to check out fish right here now fish is not without its drawbacks unfortunately so fish is not posix compliant and you might have heard that before and you didn't actually know what it meant so you're a little bit confused okay fish isn't posix compliant but is that bad do i need to care about that and so let me give you a little example right here so let me go back to zsh for a second clear this out and let's say in zsh i want to set a variable so i have this variable let's just say my var let's say i want to make that equal to hello right here so then when i echo out my var right here i'm going to get hello so that's how you set a variable in zsh that's how you set a variable in bash and it's basically the posix standard way of doing it so every shot is posix compliant this is going to work in that's how you set a variable but let's go back to something like fish so if we're using fish and we want to set a variable you can say my new var is equal to hi so we can hit that but it's not actually going to work as you can see it returns an error right here unsupported use of equals mark and that's because fish does everything differently just because it's not posix compliant so any sort of batch scripting or anything that you're used to say setting a variable or making a for loop or making an if statement all of this is going to be in a different syntax in fish so if i want to do this the fish way instead of writing this like this i would actually write set my new var to high and now i can echo out my new variable right here and that works as you would expect but if you want to use fish for scripting you're going to have to learn a lot of things new however that doesn't mean that you are never ever going to use a bash script ever again for the rest of your life so let me just show you uh batch script i have right here it's going to be dot local slash bin change volume this is just a basic script i have in order to send a notification whenever i change the volume right here and so as you can see at the top right here this is the interpreter and this is basically which shell is interpreting this right here so this is slash spin slash sh which most of the time is just going to be bash right here so we're using fish but we're still able to use this bash script right here just because we set the interpreter up here so if i want i can of course run change volume up and it's still going to work as you would expect but of course if we were to change this to something like fish and then try to use this then of course it's going to completely break nothing's going to work so for the most part you're probably going to want to continue to keep writing your scripts in bash now that might seem a little bit weird to you maybe you don't want to have a different scripting language for scripting and then a different syntax for writing your configuration file in fish for example and you can actually write this in fish but you would have to completely rewrite this script right here using fish's syntax and another drawback is that this script is not going to be very portable so if you want to send this script to your friend who also wants to have a change volume notification well you better hope that he's running fish or it's not actually going to work and that's why posix compliance was invented in the first place just because it's nice to have a standard so you can send this to another person also running a unix machine and you can expect that it's going to basically run the same as it would on your machine so if you want to write scripts and then share them with a lot of people then i would not really recommend fish but maybe you don't care about that you just want to write scripts for yourself and you don't actually care if anybody else ever uses them that's fine you can write all your scripts in fish shell i can't possibly recommend that but you can do what you want or of course you could just do like i said and then just use a different scripting syntax for writing some bash script right here and then use a different one for configuring your fish and of course you can change that in dot config slash fish slash slash config dot fish right here but inside the configuration file you would just write this in fish syntax not bash syntax of course so this if statement would not fly at all in bash but it does work in fish so you do have to keep that in mind that's what posix compliance means you're going to have different syntax and fish and if you're used to working in bash or zsh then porting everything over can be kind of a headache even something similar like aliases are done different in fish so you do need to keep that in mind but if you're the kind of person that doesn't care about bash scripting that much you don't really write that many scripts and you don't mind learning something new in order to configure a little bit maybe you don't even want to configure it that much you are pretty happy with the default configuration then go ahead and use fish but finally let's get into my recommendations and to what i actually recommend most people to use so i would still recommend most people to use zsh and just set up the configuration yourself i like zsh because it is posix compliant so i don't have to learn some new syntax when configuring it and it's a lot more easily extensible than something like bash but if you're the kind of person who's too lazy to set all that up then i would check out my zsh for humans video that installation script for zsh or just try fish give fish a shot you can always just try it out and if you find out that you don't like it you don't have to use it you can just go back to whatever you were using before and then finally i would just recommend using bash if you are working in a whole bunch of different machines that are using bash by default and you just want to be really familiar in bash i would just stick to bash but that's just a basic crash course onto the basic differences of all these obviously i could go much more into detail about all these and explain all the intricate differences between each of these shells but that would be very long i just wanted to give you an introduction if you want to do some more research you can but those are the basic differences between all of those and hopefully that makes your decision a little bit easier as to which shell you should use feel free to argue about which one is the best in the comments but that's all for now personally i'm just going to be over here enjoying my zsh configuration right here
Info
Channel: Eric Murphy
Views: 127,561
Rating: undefined out of 5
Keywords: bash, zsh, zshell, z sh, sh, dash, fish, shell, terminal, prompt, command line, best shell, difference, best, easiest, setup, configuration, posix, unix, linux, macos, windows, wsl, theme, plugins, oh-my-zsh, oh my zsh, oh my bash, oh my fish, settings, tutorial, web dev, devops, ssh, default, which, different, eric, murphy, bash vs zsh, bash vs fish, 2022, cli, tui, highlighting, colors, autosuggestions, autocomplete, fzf, tab completion, powerlevel10k, powerlevel9k, spaceship, starship, fish shell, zsh plugins, zsh shell
Id: dRdGq8khTJc
Channel Id: undefined
Length: 13min 31sec (811 seconds)
Published: Mon Nov 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.