Unique Features of bash compared to zsh

zsh is for vulcans. ;-)

Seriously: bash 4.0 has some features previously only found in zsh, like ** globbing:

% ls /usr/src/**/Makefile

is equivalent to:

% find /usr/src -name "Makefile"

but obviously more powerful.

In my experience bash's programmable completion performs a bit better than zsh's, at least for some cases (completing debian packages for aptitude for example).

bash has Alt + . to insert !$

zsh has expansion of all variables, so you can use e.g.

% rm !$<Tab>

for this. zsh can also expand a command in backtics, so

% cat `echo blubb | sed 's/u/a/'`<Tab>

yields

% cat blabb

I find it very useful to expand rm *, as you can see what would be removed and can maybe remove one or two files from the commmand to prevent them from being deleted.

Also nice: using the output from commands for other commands that do not read from stdin but expect a filename:

% diff <(sort foo) <(sort bar)

From what I read bash-completion also supports completing remote filenames over ssh if you use ssh-agent, which used to be a good reason to switch to zsh.

Aliases in zsh can be defined to work on the whole line instead of just at the beginning:

% alias -g ...="../.."
% cd ...


I would like to point out that bash is not installed by default on FreeBSD, OpenBSD, or NetBSD, and it is also not installed by default on Solaris 10 (OpenSolaris has it as the default), last time I used an AIX, and or HP-UX servers it was not installed by default either.

Also, on OpenSolaris /bin/sh is NOT bash. It is ksh. The biggest issues I have as a software porter is people that assume /bin/sh is bash and that it will accept bash extended syntax. While this seems to be the case on most Linux distributions it is not the case elsewhere and it is really annoying.


Although I am a bash user, I find one of zsh's features pretty cool: RPS1.

Remember:

  • PS1: the left aligned prompt
  • RPS1: the right aligned prompt

Sample:

When using something like

PS1=’%B(%h) %m%#%b ‘
RPS1=’(%20<…<%~)'

You get your prompt on the left and the current directory pushed onto the right. It even disappears when the current line is getting too long ! It's because zsh is smart enough to give low priority to RPS1.

You can see a screenshot of this example at http://imgur.com/OAZhC.


Zsh has spelling correction. If you're a letter (or more) off, it will figure out what you meant.

It also has more robust tab completion, which I like.

Zsh has an interactive config utility to get it set how you like.

Some speed tests say zsh is faster, but I haven't noticed any difference.