tags:

views:

2120

answers:

10
+1  Q: 

Bash or Ksh ?

I'm not new to *nix, however lately I have been spending a lot of time at the prompt to do my development for my job. My question is what are the advantages of using Korn Shell or Bash Shell? Where are the pitfalls of using one over the other? Looking to understand from the perspective of a user, rather than purely scripting.

+1  A: 

Don't forget zsh.

Hank Gay
+1  A: 

Bash is the benchmark, but that's mostly because you can be reasonably sure it's installed on every *nix out there. If you're planning to distribute the scripts, use Bash.

I can not really address the actual programming differences between the shells, unfortunately.

foxxtrot
If you are planning to distribute scripts use posix-sh. Bash is a good shell, and the default on linux. Older Unix flavors tend to have sh, ksh, and csh. In a production environment, it can be difficult to get permission or forgiveness for installing the shell of your choice on all the systems.
semiuseless
+1  A: 

For one thing, bash has tab completion. This alone is enough to make me prefer it over ksh.

Z shell has a good combination of ksh's unique features with the nice things that bash provides, plus a lot more stuff on top of that.

Allen
ksh has completion, just not with the tab key.
Dennis Williamson
+1  A: 

@foxxtrot

Actually, the standard shell is Bourne shell (sh). /bin/sh on Linux is actually bash, but if you're aiming for cross-platform scripts, you're better off sticking to features of the original Bourne shell or writing it in something like perl.

Hank Gay
+1  A: 

I don't have experience with ksh, but I have used both bash and zsh. I prefer zsh over bash because of its support for very powerful file globbing, variable expansion modifiers, and faster tab completion.

Here's a quick intro: http://friedcpu.wordpress.com/2007/07/24/zsh-the-last-shell-youll-ever-need/

Chris AtLee
+1  A: 

My answer would be 'pick one and learn how to use it'. They're both decent shells; bash probably has more bells and whistles, but they both have the basic features you'll want. bash is more universally available these days. If you're using Linux all the time, just stick with it.

If you're programming, trying to stick to plain 'sh' for portability is good practice, but then with bash available so widely these days that bit of advice is probably a bit old-fashioned.

Learn how to use completion and your shell history; read the manpage occasionally and try to learn a few new things.

Incident
+1  A: 

This is a bit of a Unix vs Linux battle. Most if not all Linux distributions have bash installed and ksh optional. Most Unix systems, like Solaris, AIX and HPUX have ksh as default.

Personally I always use ksh, I love the vi completion and I pretty much use Solaris for everything.

Kristian
HP-UX provides sh, csh, and ksh as default shells. In 11.31 bash was included on the default installation media. But, given the amount of 10.20 still running in the world, ksh is still a better bet for administering HP-UX.
semiuseless
A: 

Bash is the standard, so it is easier to find help when needed.

Matt
I'd say _bash_ is _a_ standard. ;-)
Jon Ericson
bash is only the standard for Linux. The original Bourne shell (sh) is the standard for cross-platform scripts.
Hank Gay
Posix-sh is (or perhaps 'should be') the standard for cross platform scripting.
semiuseless
A: 

For scripts, I always use ksh because it smooths over gotchas.

But I find bash more comfortable for interactive use. For me the emacs key bindings and tab completion are the main benefits. But that's mostly force of habit, not any technical issue with ksh.

Jon Ericson
+5  A: 

Bash.

The various UNIX and Linux implementations have various different source level implementations of ksh, some of which are real ksh, some of which are pdksh implementations and some of which are just symlinks to some other shell that has a "ksh" personality. This can lead to weird differences in execution behavior.

At least with bash you can be sure that it's a single code base, and all you need worry about is what (usually minimum) version of bash is installed. Having done a lot of scripting on pretty much every modern (and not-so-modern) UNIX, programming to bash is more reliably consistent in my experience.

j.e.hahn