67

I have been a zsh user for quite some time (before that tcsh and before that csh). I am quite happy with it, but was wondering if there are any compelling features of bash that do not exist in zsh. And conversely, are there zsh features which do not exist in bash. My current feel is that bash is better:

  • If you are familiar with it already and don't want to learn new syntax.
  • It is going to exist on most all *nix machines by default, whereas zsh may be an extra install.

Not trying to start a religious battle here, which is why I'm just looking for features which exist in only one of the shells.

1
  • 11
    How are features that are unique to one or the other subjective? I'm honestly not looking for a flamewar and conceed that familiarity of one or the other is likely a good reason to prefer that shell.
    – Tim
    May 5, 2009 at 22:12

10 Answers 10

41

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 ...
1
  • 8
    In bash, C-M-e to "shell-expand-line", which would expand cat `echo blubb | sed 's/u/a/'` to cat blabb and echo $SHELL to echo /bin/bash in my case. Also, C-x * to "glob-expand-word", which would expand rm *.
    – Victor
    Aug 13, 2011 at 21:31
17

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.

2
  • 7
    Yes you are right. Alas, all these vendors sure make it very very easy to install bash as an extra package. +1 for pointing out the need for /bin/sh purism in scripts.
    – kubanczyk
    Aug 22, 2009 at 11:04
  • @kubanczyk: If you're working on machines you don't have root access to, then it may not be so easy to install, so I think X-Istence's point stands. (I work on a bunch of Solaris boxes, and the sysadmins are all ksh junkies. Last time I tried to compile my own software that I couldn't live without (git in this case) there were deficiencies with the installed compiler, so even that route was cut off to me.)
    – iconoclast
    Jul 14, 2011 at 18:08
12

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 https://i.stack.imgur.com/W3qDx.jpg.

9

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.

2
  • 1
    A stripped down version of dash which supports only a subset of its features, and designed to be used in scripts which should run fast (startup ones, for example) is dash.
    – Chucky
    Mar 20, 2013 at 13:44
  • zsh even has a setting to allow for 'one letter off' mistypes for Dvorak keyboard use.
    – vgoff
    Apr 5, 2015 at 4:53
6

I don't know of any bash features that zsh does not support. The design goal of zsh seems to include supporting any features that bash adds.

I still use bash instead of zsh. I rarely come across compelling features that zsh supports that bash does not. Occasional problems with zsh over the years, or it not existing on certain sysetms, have made it not worth making the transition.

I can finally use the same shell on every Unix system, it's not worth breaking this for features I'll never use.

The features present in zsh that are not present in bash seem to mostly be cute but not ones that would matter on a day-to-day basis.

3

bash has many features that used to only be in zsh. You can have 'smart tab completion' with bash aswell now, as any recent ubuntu user has discovered.

1

Process substitution and extended globbing are the two features I would miss the most. The prompt settings are pretty cool too - seeing the level of nesting when you are typing complex statements on the command lines. Autoloading makes including lots of functions in every shell feasable.

1
  • I assume you mean you would miss those from zsh, since AFAIK everything you mentioned is included in zsh? (But are you sure they're all absent from bash? That would surprise me.) At any rate, adding that would make your answer clearer, since there are people answering on both sides of the bash/zsh fence. Also, it would be helpful if you'd give examples of how each of those features make your shell life easier.
    – iconoclast
    Jul 14, 2011 at 18:24
0

I'm a fan of zsh because of the vi mode support, but I am discovering that it's not very widely used. I think I read that zsh likes to take popular features from the other shells and combine them (so things specific to bash and thing specific to csh are both available in zsh).

Someone also said that I'm flexing my geek factor by using zsh, but I can't confirm or deny that rumor.

2
  • 5
    and yes, bash also has vi-mode support.
    – pjz
    May 5, 2009 at 21:15
  • @Milner: can you explain what sort of vi mode support is in zsh that is not in bash? If you simply mean the ability to do set -o vi on the command line, then that is clearly in both. If there is some extended support in zsh, could you describe clearly what it is and what it adds?
    – iconoclast
    Jul 14, 2011 at 18:28
-1

Popularity, #bash 430 users. #zsh 123 users. I believe the zsh website has a good comparison of zsh with other shells. zsh has better vi mode support.

4
  • 2
    How is the vi-mode in zsh better? I'm a bash user and I have vi-mode on, so I'd like to know if there's any benefit in switching.
    – ptman
    May 16, 2010 at 12:54
  • 1
    @ptman: zsh's prompt can be made to tell the mode (insert/normal). Readline can't do that. The prompter is more flexible as well: you can have syntax highlighting etc!
    – mike3996
    Mar 17, 2011 at 17:00
  • @progo: ahh! very nice. Now I just might start using vi mode in zsh. That's been one of my reasons for sticking with emacs mode so far.
    – iconoclast
    Jul 14, 2011 at 18:30
  • @Brandon that little enhancement was the reason for me to switch shells.
    – mike3996
    Jul 14, 2011 at 21:30
-1

Bash is using the same syntax for if and while as that can be used in /bin/sh scripts on the command line.
Within zsh the syntax is different. Effectively using zsh you have to remember both, if you are using an if- or while-statement on your command line

2
  • 1
    I tried this, using if [[ $test = "test" ]]; then echo "success"; else echo "failure"; fi on both the command line and a script, and it worked as expected in both cases. So it would seem that you don't have your facts straight.
    – iconoclast
    Jul 14, 2011 at 18:17
  • This depends on what you have installed as /bin/sh. If /bin/sh is bash, then you're right. Otherwise, bash doesn't have this advantage. If zsh is /bin/sh, zsh has this advantage. Given all of the different shells that could provide /bin/sh, I personally recommend just using the shell you want for shell scripting, so that its absence points to an issue with an obvious fix, rather than bizarre behaviors with no clue about how to resolve.
    – Ed Grimm
    Apr 11, 2019 at 2:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .