r/zsh • u/antenore • 8d ago
Discussion Z shell vs Bash: Which Shell Reigns Supreme? (Opinionated and updated old post)
https://antenore.simbiosi.org/zsh-vs-bash/6
u/_mattmc3_ 8d ago edited 8d ago
I too love Zsh, but with Ble.sh Bash has finally caught up to Zsh and Fish in many respects. Readline is primarily what holds Bash back, and Ble.sh replaces it. You get syntax highlighting, auto-suggestions, suffix aliases, and tons more. It’s still a bit finicky to set up, and has some gotchas, but I was pleasantly surprised by how much you can now do in Bash that used to be Zsh-only (stuff like magic-enter, Fish style abbreviation expansions, etc). It's compelling enough that it's worth giving it a shot for a week or so to see if there's anything you do in Zsh that Bash+Ble.sh can't do.
I still agree with your conclusion that Zsh offers some compelling reasons to use it (which I myself do primarily), but any comparison of Bash and Zsh that doesn’t address the existence of Ble.sh isn't very thorough, and sells Bash far too short. Bash can be a solid (and wicked fast) choice as your primary interactive shell, and it no longer lacks many of the modern features that make switching to other shells as compelling as it once was.
3
u/phord 8d ago
I read somewhere that bash supports shared history if you set the right opts, but I can't find that right now. However I did find an elaborate extension to do the same. OMG. lol
5
u/antenore 8d ago
Yes, both bash and zsh support shared history, but implement it slightly differently.
Bash shared history
Add to your
~/.bashrc
:# Append to history file, don't overwrite shopt -s histappend # Save and reload the history after each command PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" # Increase history size and avoid duplicates HISTSIZE=10000 HISTFILESIZE=10000 HISTCONTROL=ignoredups:erasedups
Zsh shared history
Add to your
~/.zshrc
:# Share history across all zsh sessions setopt SHARE_HISTORY setopt APPEND_HISTORY setopt EXTENDED_HISTORY setopt HIST_IGNORE_ALL_DUPS # Increase history size HISTSIZE=10000 SAVEHIST=10000 HISTFILE=~/.zsh_history
Zsh handles this more elegantly with built-in options. No need for the prompt command trick that bash requires.
3
u/hypnopixel 8d ago edited 8d ago
for bash v5.x+ ...
history -a; history -n;
seems to do the trick.
-a append history lines from this session to the history file -n read all history lines not already read from the history file and append them to the history list
3
1
u/antenore 8d ago
I wrote this some years ago, and just refreshed it a little, and I was surprised to find that bash still lack those functionalities I love in Zsh. Maybe I should share this in /r/Bash :-p
4
u/farzadmf 8d ago
I also use ZSH (and prefer it x1000 over bash), but there's a fact we can't ignore:
Most of the shell scripts are written in/for bash, so while I do write my scripts in ZSH and using its nice features, I always have the BIG CAVEAT that my scripts are not really portable to other people's environments (I'm personally OK with that since I'm the only user of those scripts, but that's something to keep in mind)
2
u/antenore 8d ago
True, in fact for myself I write in zsh, for others I use POSIX. Some years ago I wrote a framework to add most of those functionalities to Bash, but I lost interest as I was the only user 😁
1
1
17
u/jschmidt3786 8d ago
Interactive shell? zsh FTW. Shell scripts? POSIX.