Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm curious about why one would want to run bash instead of zsh. I mean zsh is fully backwards-compatible with bash. Don't get me wrong: I don't dislike bash or anything. I just genuinely want to know if there are any advantages to using it over zsh.

So what reason is there to use bash over zsh?

share|improve this question

8 Answers 8

Two reasons come to mind:

First -- it is available practically everywhere. I have several Linux systems (CentOS 4.x in this case) which do not have zsh installed. Similarly I have to touch ancient systems like Solaris 2.6 and up, HP-UX 10 and up, and similarly creaky versions of AIX. Therefore I pretty much have to use bash on these computers, which I do because I touch dozens, if not hundreds, of individual computers over the course of a month, and in order to get consistency in your interface you end up being stuck using the defaults.

Second -- it is available practically everywhere. This means I can write a bash shell script and be 99% sure that it will work when transferred elsewhere.

Yes, these reasons are superficially the same, but the reasoning behind them is different.

share|improve this answer

Bash generally comes with every system, zsh doesn't. I love zsh, but because of this, I use zsh for interactive use, but Bash for all my scripting.

I find this keeps everything simpler, as even when I shopt whatever the bash compatible (setopt SH_WORD_SPLIT ?), I still run into subtle differences.

share|improve this answer
3  
That would be every GNU/Linux system you mean? –  andol Dec 11 '09 at 14:19
    
Well I have found it comes with OS/X and bsd, I don't have much experience with other *nix's , do they (recent versions) not usually have bash? –  Kyle Brandt Dec 11 '09 at 14:27
1  
Older Solaris versions didn't include bash; I typically had to depend on Bourne being the shell for scripting. This hasn't been the case for a while, but you may still run into it in some big enterprises. –  user5336 Dec 11 '09 at 14:41
2  
Must been different BSD:s then. At least in OpenBSD and in FreeBSD you have to install bash separately from ports/packages. –  andol Dec 11 '09 at 15:01
    
andol: Those are the ones I used to use.. I must remember incorrectly, or I did that and just don't remember. –  Kyle Brandt Dec 11 '09 at 15:03

zsh is not fully bash compatible. There are a variety of differences. Newer zsh is more compatible with bash (=~ supported, exec now has the extra flag options, etc) but full compatibility is not a goal, not even under "emulate".

For instance, bash substring is ${foo:offset:len} but in zsh it's $foo[start,end] and that's just one simple example.

zsh is a tcsh and ksh influenced shell which does many things its own way; POSIX compatibility is explicitly not a goal, but the developers are responsive to patches which add options/emulate behaviour that get things closer to POSIX. But when you start really getting into the power of the shell, you start creating write-only scripts, more so even than bash.

bash is POSIX sh + ksh + pedanticism, with some features now copied from zsh. It too has write-only scripts but because it has less powerful operators, you end up not using the conciseness of zsh and things might be more readable (except for all the quoting to avoid whitespace split, the stupid ksh-style $array means first-element-of-array, not all-elements-of-array, etc etc).

Writing scripts which take full advantage of the power of either shell is unwise, unless you're in a constrained environment (eg, writing system rc scripts, where some FSs might not be mounted, etc). As an ideal, use Perl/Python/Ruby/whatever for anything big enough that you need the expressiveness not in Bourne sh, if you want others to be able to maintain it. Keep the shell stuff for things relating to the interactive shell (tab completion programming, etc).

I wouldn't use bash over zsh. I'd use bare sh over zsh for simple scripts, or switch to a language where associative arrays have decent operators (unlike in zsh, where they are, again, 'concise'). I might switch a sh script to bash if I need that one little feature to extend an existing proven-working script and don't have time to rewrite it now.

share|improve this answer
2  
nb: ${foo:offset:len} is now supported in zsh, for compatibility. –  Phil P Aug 30 '11 at 9:18

My advice: if you are going for absolute portability, write using Bourne shell rules, don't even bother with Korn shell extensions. As mentioned, that are some older "big boxes" around that don't have GNU shells on them at all.

Bash already does "too much". I have a friend at work who prefers zsh, but I don't know what exactly it does.

Anyway, either write for Bourne (or "bourne again") shell, or alternately, if you are doing a custom script for a small number of specific boxes, skip "shell hell" entirely, and just write using perl or python (or whatever your favorite locally installed interpreter is).

share|improve this answer

By the way, you have been told here many times that bash is found practically everywhere, so use it to write portable scripts, which is false.

Nonsense. If you know that every system you care about has BASH then it's a perfectly reasonable statement. BASH has many useful features that can't be reasonably emulated in POSIX sh. Frivolous use of non-POSIX features is not a great idea but using them when you genuinely need them is fine.

Portability is not an absolute. It's arguable how far you need to take it, just like anything else. For example, Fedora uses shell commands for building RPM packages and the Fedora packaging guidelines state that since all packages must be built natively on Fedora, it's fine to use all the features of BASH. Even though theoretically other distros without BASH may want to reuse their source RPMs, they made a decision about portability based on practicality instead of your "ALWAYS UZE POSIX!!1" mantra.

ZSH hasn't caught on as a default shell, simply because it's a sprawling mess of half-baked ideas.

share|improve this answer

In addition to the portability reason given above, another one might be that bash is still adding features.

For example bash v4.x+ introduced:

  • recursive globbing:

    rm -f **/*.log

  • autocd:

    Type "/tmp" instead of "cd /tmp"

share|improve this answer
    
How is bash copying features from zsh a reason to use bash? –  qqx Oct 27 '12 at 20:35

By the way, you have been told here many times that bash is found practically everywhere, so use it to write portable scripts, which is false.

The right way to write portable unix scripts is to use sh, which is found in every *nix system.

Every other shell except sh is just a daily interactive tool of yours.

When coming to bash vs zshbash is bundled in more *nixes than zsh, so here comes disadvantages of installing additional software to the system — you have to maintain it. Some folks love zsh "cool features" so they like to pay that price, some not.

share|improve this answer
1  
Many modern implementations of sh are just links to bash. –  Iain Aug 21 '12 at 11:39
    
@Iain Ubuntu uses dash by default, and even if sh is bash, it enables compatibility mode when run as sh. –  mgorven Aug 25 '12 at 3:39

Another point:

Many programs provide cool bash completion by default. For me it's the reason to not switch.

[added in Jul 2013] Well after few years of using zsh since the comment above, I have to say tab completion (even builtin one, w/ no 3rd-parety modifications) is brilliant and looks like it's far beyond the one offered by bash. :).

share|improve this answer
3  
I think that works with ZSH as well, with tab completion in ZSH, I get lots of program specific arguments ... –  Kyle Brandt Dec 11 '09 at 14:43
    
Interesting. Are you saying that bash completion files work with zsh, or just some programs have its zsh-specific completion stuff? Still there's some std layout of bash completion files which zsh may or may not consider automagically. Have you tweaked your zsh config to make it work? –  Wojciech Kaczmarek Dec 11 '09 at 15:13
    
@Wojciech Kaczmarek: I think you want the 19.3 from the following: zsh.sourceforge.net/Doc/Release/zsh_19.html . Honestly, I never took the time to really understand it, just ripped off a .zshrc I found online :-) But it will complete command line arguments from programs like apt, grep, etc.... –  Kyle Brandt Dec 14 '09 at 12:41
    
Thanks! Will try. –  Wojciech Kaczmarek Dec 14 '09 at 18:42
5  
bash's tab completion is very similar to zsh's old tab-completion system. This is one of the ideas copied from zsh to bash (there are others copied bash to zsh). You can use completion scripts written for bash in zsh, by running "bashcompinit" and then using the "complete" and/or "compgen" commands inside zsh -- this is possible because the bash functionality is a subset of that available in zsh and so can be emulated. So there's no reason to switch to bash because a command ships with a bash completion. –  Phil P Jan 2 '10 at 3:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.