What features are in zsh and missing from bash, or vice versa?
There's already been quite a bit of activity on the topic on other Stack Exchange sites. My experience of switching from bash to zsh, as far as can remember (it was years ago²), is that I didn't miss a single thing. I gained a lot; here are what I think are the simple zsh-specific features that I use most:
The zsh feature I most miss when I occasionally use bash is autocd: in zsh, executing a directory means changing to it, provided you turn on the
autocd
option.⁴Another very useful feature is the fancy globbing. The
hieroglyphscharacters are a bit hard to remember but extremely convenient (as in, it's often faster to look them up than to write the equivalentfind
command). A few of the simpler examples:
foo*~*.bak
= all matches forfoo*
except those matching*.bak
foo*(.)
= only regular files matchingfoo*
foo*(/)
= only directories matchingfoo*
foo*(-@)
= only dangling symbolic links matchingfoo*
foo*(om[1,10])
= the 10 most recent files matchingfoo*
foo*(Lm+1)
= only files of size > 1MB
dir/**/foo*
=foo*
in the directorydir
and all its subdirectories, recursively⁴For fancy renames, the
zmv
builtin can be handy. For example, to copy everyfile
tofile.bak
:zmv -C '(*)(#q.)' '$1.bak'
Both bash and zsh have a decent completion system that needs to be turned on explicitly (
. /etc/bash_completion
orautoload -U compinit; compinit
). Zsh's is much more configurable and generally fancier.
If you run zsh without a .zshrc
, it starts an interactive menu that lets you choose configuration options. (Some distributions may disable this; in that case, run autoload zsh-newuser-install; zsh-newuser-install
.) I recommend enabling the recommended history options, turning on (“new-style”) completion, and turning on the “common shell options” except beep
. Later, configure more options as you discover them.
²At the time programmable completion was zsh's killer feature, but bash acquired it soon after.
⁴Features that bash acquired only in version 4 (so are still not available on many systems) are in smaller type.
Also the default tab completion is better than bash... for example...
~/.e.d
TAB will expand to ~/.emacs.d/
in zsh, bash will just beep.
zsh
lets you edit a multi-line command (see zsh line editor), bash doesn't. If you try the same trick (Ctrl-p
), bash fetches the last command.