I have been a user of Bash for some time. I want to learn at least one other shell now, so I have been picking up the Korn Shell. However, it doesn't look like Ksh has had major updates for almost twenty years, and I have read that Zsh incorporates features from it. I have been reading many of the shell comparison questions on the StackExchange network, but have not found an answer to this: Are there features from Korn Shell that Zsh does not incorporate? If so, what are they?

  • 1
    ksh is still in active development. To just scratch the surface, see my long comment (as an answer) at stackoverflow.com/questions/5479433/… . I don't use zsh, partly for corporate reasons, but bahamat's answer below gives some good reasons to look at it. Good luck. – shellter Jun 27 '12 at 23:46
  • 2
    I think zsh has all the major features of ksh93 and most of the minor features, but often with a different syntax for those features that weren't around in 1993. – Gilles 'SO- stop being evil' Jun 28 '12 at 0:49

Here's the Wikipedia article on command shell comparison.

According to that, the only feature ksh has that zsh doesn't is Named parameters for user defined "types". There may be others as that article is not an exhaustive list, especially for obscure features.

Going in the other direction, the answer to your question could fill a book (possibly this one).

Zsh has many features that ksh doesn't. A few popular ones are command stack, directory stack, history sharing and rprompt.

  • Command Stack is when you're typing a command and you realize that you should run another command first. Just send the current line to the command stack, run the other command then pop the command off the stack. You can do this multiple times. (zsh is the only shell I know of that provides this).
  • Directory Stack (aka pushd/popd) is when you want to change to directories in succession then cd back in reverse order. (Many shells provide this, including bash).
  • History Sharing is where every open shell shares a single common history. Execute a command in one window, switch to another and it will be available in your history.
  • rprompt is just like your prompt, except it's right justified. Many people like to put the cwd or date in the rprompt.

Here are some discussions on Stack Exchange sites about zsh:

  • D'oh. Well, then according to that Wikipedia article, the only feature ksh has that zsh doesn't is Named parameters for user defined "types". – bahamat Jun 29 '12 at 22:07
  • @Kazark: there you go. – bahamat Jun 29 '12 at 22:20

ksh88, the most famous variant as it was included in SVR4, the language bash is mostly based on, the one pdksh partly cloned, and whose subset is the basis for the POSIX specification of sh has not evolved much (apart from some bug fixes and POSIX alignments by some vendors) since its last release in May 1993 (ksh88i).

However, ksh93, a rewrite by David Korn, first released in December 1993 has been in active development until around 2014 and its source code was freed in 2000. The last official release, ksh93u+, was made in August 2012 (only a few weeks after you asked that question), and there was a "beta" release (ksh93v-) made in 2014 by the original authors after they were made redundant by AT&T with many new features.

There has been a community effort to carry on development and modernise the code, based on ksh93v- which led to a ksh2020, but that effort has now been abandoned. A separate effort to maintain ksh93u+ after that seems to be going the same way. While a new one (ksh93u+m) looks a bit more promising at the moment.

ksh93 is/was more than a shell. It was developed alongside a fleet of utilities reusing some of the same code and that could be made builtin in ksh93, a bit like busybox.

Note that it was more a research effort, is often considered experimental and is very under-documented.

While zsh was first and foremost developed to be a powerful interactive shell, ksh93's focus was more as a programming language. There have been a lot of effort on the language and on optimisation with a goal to be in a similar category as perl or python for instance.

There are many many features of ksh93 that zsh hasn't, like there are many many features of zsh that ksh93 hasn't, and both have borrowed feature from each other. There is a large set of common features, and there are things that both can do but in very different ways.

Among the things ksh93 has but zsh doesn't:

  • all the builtins of ast-open: ksh93 when built as part of ast-open has a lot of builtins that zsh doesn't have including improved versions of some standard utilities like date, join, head, tr, uniq, wc... (though zsh has some of the functionality of those in its own builtins or language features). That's the optimisation side of things. You can't be perl-like if you need to fork a process to do anything.
  • non-forking command substitutions ($(...)), and command substitutions that don't create a subshell environment ${ ...; }.
  • multidimensional arrays: a=((a b) (c d))
  • object-oriented programming features (types, structures, disciplines, methods...).
  • static scoping for variables and options (zsh has private for variables, but no static scoping for options).
  • name references (essential for a shell with static scoping and object programming structures, not so much with those with dynamic scoping like zsh or bash)
  • date/time manipulation including with natural language, crontab, iso formats in its printf and date builtins (zsh's strftime is very limited compared to that).
  • a few useful redirection operators (<#((...)) for seeking, <>; to overwrite and truncate...).
  • namespaces
  • job pools and coshells.
  • CSV/URI/HTML-entities/base64 encoding/decoding.
  • json encoding/decoding in ksh93v- to (de-)serialise its advanced data structures in a format that other tools can understand (very buggy, removed in ksh2020).
  • $"..." for message localisation
  • /dev/tcp, /dev/udp (zsh has ztcp, zsocket for UNIX domain sockets, but no UDP)
  • there also was a dtksh shell that add X toolkit functionality to ksh93 included in CDE in the 90s.
  • there's a shcomp to compile ksh code.
  • Very good answer. We are still using ksh93 for many of the reasons above, top reason being extreme speed superiority. – gsl Sep 15 '20 at 9:51
  • PS: See a nice thread about speed here – gsl Sep 15 '20 at 10:59
  • 1
    @gsl, you'll notice I participated in that thread. What makes the most of the difference there is that ksh93 doesn't fork for cmdsubst (it's not the only shell, that's also the case of fish, FreeBSD sh (for some builtin commands), and mksh has some non-forking cmdsubst operator variants). In other shells, you'd use tempfiles to achieve the same or would return value using variables instead of output, but here I'd argue it's not the right way to use a shell. – Stéphane Chazelas Sep 15 '20 at 12:30
  • 1
    @gsl, for the record the equivalent zsh code for that fib function (fib() (( $1 < 2 ? $1 : fib($1 - 2) + fib($1 - 1) )); functions -M fib 1 1; echo $(( fib(20) ))) is twice as fast as ksh93, 3 times as fast as ksh2020 (in addition to being shorter and more legible), but of course orders of magnitude slower than the equivalent in a proper programming language, showing that it's more about picking the right tool for the task, and use each tool as it's meant to. – Stéphane Chazelas Sep 15 '20 at 13:18
  • Wonderful, thanks for the additional clarification. – gsl Sep 15 '20 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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