Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash or KornShell (ksh)? [closed]

I am not new to *nix, however lately I have been spending a lot of time at the prompt. My question is what are the advantages of using KornShell (ksh) 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.

like image 278
user13158 Avatar asked Sep 16 '08 17:09

user13158


People also ask

Is ksh same as bash?

Bash and KSH are both Bourne-compatible shells. Since they share common features, they can be used interchangeably.

Which is better ksh or bash?

Korn shell provides much better performance than Bash shell when dealing with the execution of scripts and commands. Bash shell provides decent performance when it comes to executing commands and scripts. Korn shell interpreter is located at /bin/ksh. Bash shell interpreter is located at /bin/bash.

What is ksh in shell script?

The ksh command invokes the Korn shell, which is an interactive command interpreter and a command programming language. The shell carries out commands either interactively from a terminal keyboard or from a file.

What is the difference between Korn shell and bash shell?

Korn shell uses the print command to print the message in the terminal. Bash shell uses the echo command to print the message in the terminal. Korn shell has better support to loop handling as compared to the Bash shell. The Korn shell is developed by David Korn and it's older than the Bash shell.


1 Answers

The difference between Kornshell and Bash are minimal. There are certain advantages one has over the other, but the differences are tiny:

  • BASH is much easier to set a prompt that displays the current directory. To do the same in Kornshell is hackish.
  • Kornshell has associative arrays and BASH doesn't. Now, the last time I used Associative arrays was... Let me think... Never.
  • Kornshell handles loop syntax a bit better. You can usually set a value in a Kornshell loop and have it available after the loop.
  • Bash handles getting exit codes from pipes in a cleaner way.
  • Kornshell has the print command which is way better than the echo command.
  • Bash has tab completions. In older versions
  • Kornshell has the r history command that allows me to quickly rerun older commands.
  • Kornshell has the syntax cd old new which replaces old with new in your directory and CDs over there. It's convenient when you have are in a directory called /foo/bar/barfoo/one/bar/bar/foo/bar and you need to cd to /foo/bar/barfoo/two/bar/bar/foo/bar In Kornshell, you can simply do cd one two and be done with it. In BASH, you'd have to cd ../../../../../two/bar/bar/foo/bar.

I'm an old Kornshell guy because I learned Unix in the 1990s, and that was the shell of choice back then. I can use Bash, but I get frustrated by it at times because in habit I use some minor feature that Kornshell has that BASH doesn't and it doesn't work. So, whenever possible, I set Kornshell as my default.

However, I am going to tell you to learn BASH. Bash is now implemented on most Unix systems as well as on Linux, and there are simply more resources available for learning BASH and getting help than Kornshell. If you need to do something exotic in BASH, you can go on Stackoverflow, post your question, and you'll get a dozen answers in a few minutes -- and some of them will even be correct!.

If you have a Kornshell question and post it on Stackoverflow, you'll have to wait for some old past their prime hacker like me wake up from his nap before you get an answer. And, forget getting any response if they're serving pudding up in the old age home that day.

BASH is simply the shell of choice now, so if you've got to learn something, might as well go with what is popular.

like image 193
David W. Avatar answered Sep 20 '22 05:09

David W.