21 ms·
s/bash/zsh/g
- xyzzy_plugh 5y agoI don't know. I can't do it. Bash is the devil I know. But zsh doesn't even use readline, which is bananas to me. Sure, provide an alternative but at least support readline.
- soraminazuki 5y ago> But zsh doesn't even use readline, which is bananas to me. Sure, provide an alternative but at least support readline. Why? ZLE is what makes zsh compelling for users. It provides a high level of customizability into command line editing that is simply not possible with bash. It powers zsh's most touted completion feature as well as popular plugins such as zsh-syntax-highlighting[1] and zsh-autosuggestions[2]. Replacing it with readline would be a sure way to lose a majority of users in a blink of an eye. [1]: https://github.com/zsh-users/zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting [2]: https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions
- xyzzy_plugh 5y ago.inputrc should be universal, and it is nearly. But not here. I don't want to have customize each tool individually.
- Veliladon 5y agoYou want independent projects to agree on something? You do realize this is open source, right?
- xyzzy_plugh 5y agoThey don't have to agree on anything, just use readline. It's already used by, or optionally used by, tons of software. Here's a non-exhaustive list that immediately come to mind: bash rc psql bc ftp GDB GPG Guile Lua NetworkManager Parted Python Ruby SQLite wpa_supplicant
- soraminazuki 5y ago> .inputrc should be universal Absolutely not. Using readline means completion and keybinding customization would be limited to what bash can do, or even worse as is typical with other readline based REPLs. What you're asking for is to gut a definitive feature of zsh only so that it can be bash. That provides zero value to zsh users.
- protomyth 5y agoIs there a way to change the autocomplete key in zsh from tab to esc? I know it's a minor thing but it really does screw up my desire to switch. I looked around and the solution wasn't obvious or my google-fu is severally lacking.
- nerdponx 5y agoIt's probably possible, look up ZLE and the `bindkey` builtin.
- arp242 5y agoThis probably does what you want: bindkey '^[' complete-word You can also use "expand-or-complete", which is what Tab is mapped to by default and will also expand things (e.g. "ls *<Esc>" will expand the "*"). You may want to set lower KEYTIMEOUT too, so it doesn't wait as long for further keys after an escape. I'm not sure what the default is.
- zibzab 5y agoWe had _just_ settled the emacs vs vi argument when this starts ... I guess debian/ Ubuntu folks will choose bash, osx people will continue using zsh and the openbsd users will keep using that vanilla sh because of the vintage feel. On a more serious note: I can't see my commands in manjaro thanks to all the bells and whistles. For some reason that situation reminds me of spacemacs users.
- todd8 5y ago> We had _just_ settled the emacs vs vi argument when this starts ... We did? That’s news to me!
- zibzab 5y agoYes, we are all switching to vscode.
- mhd 5y agoPeople who switch to vscode probably also switch to fish anyway. Hmm, in this false analogy game, what editor is aligned with korn shell? xemacs?
- quicklime 5y agonvi OpenBSD (as well as the others?) come with pdksh and nvi out of the box.
- mhd 5y agoProbably closer to vile or elvis if we're talking proper ksh93.
- zamalek 5y ago> probably also switch to fish anyway. I feel attacked. In all seriousness: so long as you have a POSIX shell available (and set as default), you don't have to use a POSIX shell. I rarely do anything with fish syntax because I mostly use it for the REPL experience.
- gruturo 5y agoWhat an unazshedly interesting article.
- nerdponx 5y agoI use Zsh, it's such a tremendous improvement over Bash. Not only does it handle parameter expansion much better than any Unix-style shell, but it also has a lot more useful built-ins that can save you from having to call out to external programs to do basic tasks, like getting the absolute path of the directory that contains the current script. It is so unbelievably feature-rich that it's almost impossible to describe all of its features and merits, but you can safely ignore most of them and the basic day-to-day experience will just be "Bash, but better". No program is perfect, but Zsh I think is pretty damn close. That's not because it doesn't have flaws (it definitely has flaws), it's because it does such a good job at doing what it does, that all its flaws seem minor and none of them fundamentally get in the way of it doing that job. One additional thing I'll say is: it is probably the only Unix-style shell where I would feel comfortable writing 1000+-line applications with a CLI, tests, etc. I would never do such a thing with Bash or some minimal Posix-compatible shell. It's a very sensible system scripting language, alongside Python, Perl, etc.
- tut-urut-utut 5y agoIt may be better bash, but it's just an incremental improvement, no more. It still follows the same philosophy as bash. On the other hand, fish shell feels like a bash rethought and optimized for interactive use. It's now my daily driver on all of my Linux and Windows machines (msys2 port). After using it only for interactive sessions, I also started to write my utilities in fish, which is a breath of fresh air compared to both bash and zsh. The only place where I still use bash is when I need to write a script that needs to be shared with others, everything else is now fish.
- inkyoto 5y ago> it's just an incremental improvement, no more. It still follows the same philosophy as bash. It is actually the other way round, with bash being an incremental improvement over zsh. Starting from v3, bash has adopted many features that zsh had had for a long time. Both, bash and zsh, are incremental improvements over the Korn shell.
- nerdponx 5y ago
- tyingq 5y agoWhile these are good examples of some of the fragile parts of bash, I think switching shells is the wrong approach in this case. If you find yourself dealing with binary data, floating point math, complex quoting, and so on...you probably shouldn't be scripting with a shell. Use Python, Perl, Ruby, or something else more suited to the task.
- nerdponx 5y agoI don't agree with this. Shell syntax is uniquely flexible and powerful when it comes to composing pipelines. It often is precisely the right tool for the job. Floating point math and "complex" quoting come up pretty often in a wide range of relatively basic tasks. Even something as simple as computing a percentage literally cannot be done in Bash without forking out to an external program. Sure, you could use a tool that does that one thing and does it well, or you could just have it in your shell and not worry about it. The whole point about quoting is that it's hard to get right even when you're trying. It gets even harder when you are dealing with things like arrays and command substitution. You could switch to another programming language... or you could just use a shell that does these things right from the outset!
- vips7L 5y agoOr use powershell and have all the power of C# at your finger tips and shell scripting at the same time!
- 5y ago
- jeffrallen 5y agoConcerning the first example, if you're doing floating point in bash, you're doing it (scripting) wrong...
- 1vuio0pswjnm7 5y agos/bash/sh/g where sh is NetBSD's ash, with command history
- shantnutiwari 5y agoWhat I like best about zsh is how easy it makes normal tasks. * dont know the full name of the folder you want to cd into? Type the 1st few characters, and press tab, zsh will let you select which one you want * Oh, and search is case insensitive. No more spending hours banging at the tab, wondering why autocomplete isnt working, just because you typed "projects" instead of "Projects" * history search is great-- type the 1st few lines of a command and press up, it will take you to the last time the command was used * Oh my zsh gives you a lot of cool utilities-- instead of git commit -a -m "message" I can do gcam "message" Moving to zsh was the best decision I made.
- yjftsjthsd-h 5y agoI feel obligated to point out that this is mostly doable with BASH. * I don't understand how this is different than usual tab-completion; might just be missing something. You can stick `set show-all-if-ambiguous on` in .inputrc to make it activate on 1 tab instead of 2. * `set completion-ignore-case on` in .inputrc * https://askubuntu.com/questions/59846/bash-history-search-partial-up-arrow https://askubuntu.com/questions/59846/bash-history-search-pa... * `alias gcam='git commit -a -m'`, although I assume you're pointing out that it gives you a bunch of default aliases?
- wener 5y agoWait, are you talking about zsh or bash, because my bash have them all, what's next ?
- freeplay 5y agoI use zsh as well but most of what you highlighted is easily done in bash > Oh, and search is case insensitive. No more spending hours banging at the tab, wondering why autocomplete isnt working echo 'set completion-ignore-case On' >> ~/.inputrc > history search is great-- type the 1st few lines of a command and press up, it will take you to the last time the command was used CTRL+R and begin typing. CTRL+R again to go to next result. > instead of git commit -a -m "message" I can do gcam "message" echo 'alias gcam="git commit -a -m"' >> ~/.bashrc
- jdhendrickson 5y ago
- hd4 5y agoI strive to use bash as minimally as possible anyway, I don't quite see the point of switching to zsh when I want to avoid doing things in the shell (rather than scripting or using cron jobs or similar). Why would people want to use an alternate shell? How much do you need to be constantly sat in the shell typing out the same commands rather than either scripting them away or doing something within a text editor?
- UI_at_80x24 5y agoI'm a sysadmin. I manage 100+ remote servers, all through SSH. I _LIVE_ in the CLI. 90% of my day. And I have anywhere from 2-8 terminal windows open at a time. I've automated what can be automated, so I'm not doing this out of ignorance. I prefer the CLI too. every CLI based program I use is more performant then a GUI counter-part. If ZSH solves 10% of my BASH headaches then that equals a HUGE reduction in the effort of doing 'work'. It's ok that you don't like the CLI.
- hd4 5y agoIt's not that I don't like it, I just don't see the purpose of remaining there once I'm done writing a script or whatever. Your use-case is one of those where it does makes sense to do that.
- jfrunyon 5y ago> NUL bytes aren’t that uncommon, think of e.g. find -print0, xargs -0, etc. That all works grand, right up to the point you try to assign it to a variable. Well, duh. Environment variables are NUL-terminated. I don't understand arguments like this. "Learn something new so that you can avoid learning something old". None of the arguments on this page show me that zsh has a shallower learning curve than bash - only that zsh makes "more sense", once you've learned it, to you.
- soraminazuki 5y ago> Well, duh. Environment variables are NUL-terminated. Shell variables aren't the same thing as environment variables.
- jfrunyon 5y agoOh, great. Except uhh... they are. Shell variables are inextricably tied to environment variables and frankly, making them uninheritable would make them less useful, not more.
- soraminazuki 5y agoThey're not. Here's proof: $ unset x $ x=1 $ env | grep '^x=' It's perfectly valid and common to create variables that aren't environment variables. Variables silently dropping off characters causes problems for these use cases. For that reason, inextricably tying normal variables to environment variables would make them less useful, not more.
- jfrunyon 5y ago> It's perfectly valid Yes. > and common Not even remotely. > Variables silently dropping off characters causes problems for these use cases. Sure, you should just silently drop it off when you export it instead, because that makes far more sense.
- 5y ago
- encryptluks2 5y agoI like bash completion much more than zsh. I tend to write all my scripts to be POSIX compliant anyhow, so zsh vs bash isn't really a thing for me. However, I can see how easy it would be as a Mac user to bash bash, because often people just feel the need for validation.
- asguy 5y agoOS X is also shipping with a bash from the previous ice age. So I can see why it gets hate, it's just hate probably directed at the wrong place.
- sigzero 5y agoUse what you like. I use zsh at home. At work, it is ksh, sh, or bash on the servers. I don't see that changing (except ksh going away when we replace Solaris) for a very long time, if ever.
- juvenalmuniz 5y agoBash is not perfect and that's ok. It can't handle floating point math? bc can, so use it. That's the beauty of the Unix philosophy.
- tharne 5y ago> Bash is not perfect and that's ok. It can't handle floating point math? bc can, so use it. That's the beauty of the Unix philosophy. Nailed it. It's perfectly okay that bash doesn't have every feature under the sun because it's main goal is to let the user interact with the OS, which includes calling the right program for the right job.
- ltbarcly3 5y agoUnfortunately zsh is not fully compatible nor a feature superset of BASH so it isn't always able to replace it. Very glad I switched though!
- wchar_t 5y ago> Click to see NSFW content. Not suitable for children under 18! click > For example, this can be used to show the longest element in an array: > print ${array[(r)${(l.${#${(O@)array//?/X}[1]}..?.)}]} Got me there :^)
- emptyparadise 5y agoPerl?
- throwaway984393 5y agoPeople talk about zsh being more advanced than Bash as if that's a good thing. But remember the shell is mostly useful as an interface to other programs; it's not supposed to be filled with features. Bash has way too many features, I think, for the same reason zsh does: people thought it was philosophically superior to rely on the shell having built-in features, rather than finding or developing composeable applications..
- cabalamat 5y agoI always use bash, because it's the only shell that is 100% compatible with bash. I've heard of some things not working in other shells, and since bash works for the things I use it for, I have no reason to change.
- pdpi 5y agoThat is, ironically, one of the main reasons I decided to switch to fish instead of zsh — it’s even less compatible with bash. I’ll never be in a position where a script is subtly broken because it’s running in zsh instead of bash. Rather, it’ll just fail altogether and I can work from there.
- arp242 5y ago> I’ll never be in a position where a script is subtly broken because it’s running in zsh instead of bash I would set the hashbang to "#!/usr/bin/env bash" and then bail out if $BASH_VERSION isn't set on the first line, while also naming the script "foo.bash" (rather than foo.sh). This way you can "enforce" a specific interpreter. Scripts using #!/bin/sh while relying on bash features was a common annoyance when I used FreeBSD – although it's probably less common now that some Linuxes have started using dash and /bin/sh. I don't mind if people use bash, but please make it explicit, especially because these types of errors are not necessarily obvious to the user.
- arp242 5y agoIt's not just about "more advanced", it's also about being less surprising and having fewer caveats. And besides, if you're going to add things like globbing in your shell then you might as well do it in such a way to make it much more useful for common operations.
- HKH2 5y agoShould people new to shell programming learn zsh?
- tharne 5y agoNo. Learn Bash. The biggest benefit of bash is that you're virtually guaranteed to find it on any linux server. It's ubiquity is its strength. Write a bash script once and take comfort in the fact that it will be able to run on virtually any server for years to come. Does bash have a bunch of cryptic syntax and weird quirks? Sure, but that cryptic syntax and those weird works should remain pretty stable in the coming decades.
- lprd 5y agoNope, learn bash. Its the default on every system.
- arp242 5y agoDepends a bit why you're learning shell programming. If you want to write scripts for your personal use, or maybe for some project you have then I recommend zsh as it's so much more useful and easier. The zsh User Guide is quite good by the way (not updated in a long time, but still relevant). I you want to write shell scripts at $DAYJOB or some such bash is probably the wiser choice, as it's just more common. Whether that's a good or bad thing is kinda besides the point here; it just is.
- accelbred 5y agoFor your interactive shells, of course. There are many conveniences over bash and far better autocompletion. For scripts? Use Posix sh.
- assbuttbuttass 5y agoI tried switching to zsh, but I felt like out of the box it's almost the same as bash. I don't want to spend a lot of time configuring my shell, I want it to get out of my way and let me type commands. I use fish shell mostly these days. Magic autocompletion is life-changing.
- eatbitseveryday 5y agoI use “oh my zsh” with zsh for this reason. Installing that is as much overhead as installing zsh as a package. https://ohmyz.sh/ https://ohmyz.sh/
- PennRobotics 5y agoWhether you use bash, zsh, or most any other shell, back up your configuration files. On almost any internet-connected system, I'm three steps away from my setup: 1. Install prereqs with package manager (curl, git, zsh, vim) 2. Download and install oh-my-zsh 3. Pull .zshrc, .vimrc, etc. from Github 4. (optional) Add workarounds because Windows Terminal still can't handle color and cursor position codes.
- andrewshadura 5y agoI tried zsh, but it was slower than bash in some cases and less convenient in others, so I switched to fish instead. It fixes some of the rough corners of most Bourne-derived shells, but also provides great user experience out of the box.
- acdha 5y agoI switched to fish a few years back after a couple decades of using bash. It took about 10 minutes to make that permanent everywhere – because so much is built-in and the defaults are good, there was no need to spend time on more than the package install plus chsh. For scripting, I’d already set a personal policy that anything complicated use Python. For me there’s a fairly big difference between interactive shell sessions and scripts which solidly shifts the balance to a full language with a rich standard library and robust error handling. My scripts were edited using shfmt and shellcheck interactively anyway, so switching to Python wasn’t an increase in terms of tool support and the richer language means that I’m writing less code to get more functionality and especially error handling.
- indigodaddy 5y agoI tried out zsh and just could not get used to how different tab completion was vs bash, so went back to bash quickly. Is tab completion on fish more similar to bash than zsh is?
- MiguelX413 5y agoI use zsh because of its tab completion lol
- kbd 5y agoTotally. And there’s nothing better than fzf-tab https://github.com/Aloxaf/fzf-tab https://github.com/Aloxaf/fzf-tab
- MiguelX413 5y agoI'll try it out!
- cookiecaper 5y agoTry it for yourself: https://rootnroll.com/d/fish-shell/ https://rootnroll.com/d/fish-shell/
- myrandomcomment 5y agoSo I read this with a great deal of interest and nodded my head say “yes, that’s true” at most of it. Despite this I just do not want to switch. Heck, first thing I do when I get a new Mac (now that ash is the default)is switch my shell to bash, install homebrew, then tmux, vim, powerline and git pull my dot files. I think maybe I am just old. Get off my lawn! I am really working on not writing every little thing I want to script as a shell script. The other day I wanted to scan a dir of ~10k image files and move anything that was corrupt to another dir. I wrote it in bash and it worked. Then I was like, okay you should write this in python because you want to run it on 4 different OS. So I did. The code looks so much cleaner but was half as fast as the shell script. Oh well.
- nickthemagicman 5y agoI agree. There's perfectly good scripting languages if I need to do anything beyond bash.
- revscat 5y agoAlso agree. For me, I want to be able to do simple "for each file run this command" loops in the shell. But if those loops get much more complicated than that then I switch over to Ruby.
- nickthemagicman 5y ago*Tilt whisky glass your way. "Bravo sir."
- i2shar 5y agoThis is me as well - unabashedly a bash person. My reasons to not switch are not driven by the feature set offered by the various shells, but by the fact that I don't want to learn/think or be bothered with the nuances when I log in to various remote hosts, containers, and what have you. When I write shell scripts or installers, I want a single language that is reasonably likely to be present wherever it runs - and that today is bash.
- coliveira 5y agoI tried zsh and have not found anything that is truly superior to bash. After some investigation, it seems that this idea of moving from bash is based more on the fact that zsh is the default for Apple, due to their dispute with GNU licensing terms.
- wruza 5y agoHonestly, all these shells are too simple or at least too generic-task oriented. For me, and I guess most users, the shell is not where I live, but where I do recipes. It would be nice to have a shell+vim style shell where you edit your command plan and can see its execution results right below the commands after pressing <C-CR>: ### cwd: /some/path cd /home/user/mysvc … cd /etc/systemd/system … sudo ln -s /path/to/mysvc.service … git pull … sudo systemctl restart mysvc … tail -f /path/to/log.txt #! lines=10 nowrap autorun …(10 lines) So you could move and edit pages (or OBTF) of recipes and see their status right there. My observation is that all you do in a shell is following some patterns again and again. For example, select last three commands and hit C-CR to execute them.
- Tyr42 5y agoI agree, but I got pretty far towards this when I got fzf's ctrl+r replacement to search history quite nicely. Before I used to also have a per folder history file, so I could pull up the last thing I did there. That also helped a lot, especially when switching between different personal projects and forgetting how it all works.
- amachefe 5y agoAfter going through the article i was surprised i liked many of the bash behaviors that the author complained. The test I prefer to do with python. My conclusion is that it looks like the author wants to use a shell like a programing language.
- cracauer 5y agoI have libraries of functions written in pure sh. I use those functions in both scripts and my interactive shell (which is bash). I cannot do the same with zsh as my interactive shell if scripting is supposed to stay POSIX/bourne shell. Which I want as I often do this in systemwide scripts or modify existing scripts (all plain sh). The incompatibilities do matter.
- nixpulvis 5y agoAh yes, the hidden wisdom of Bash. Avoid floats at all cost ;) Practically, I find myself typing `irb` before every quick arithmetic session anyway... but w/e.
- dyingkneepad 5y agoOr pipe everything to bc -l, then print the result with /usr/bin/printf
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- nixpulvis 5y agoTIL: bc has a (poorly labeled) -l flag which also sets the scale to 20 for you.
- kbd 5y agoWow, been using Zsh for a while, didn't know about short loop form.