LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2010, 03:38 PM   #1
dev_d
LQ Newbie
 
Registered: Feb 2010
Location: Tempe, Arizona
Distribution: Ubuntu
Posts: 12

Rep: Reputation: 0
Whats the difference between ksh and bash?


what are significant differences between ksh and bash? I read somewhere that ksh is proprietary shell and bash is completely open source.
 
Old 02-24-2010, 03:42 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
I actually had to look up some features between various shells recently that I don't frequently use and ran into this chart, it might answer some of your questions at least on the technical aspects.

http://www.unix.com/answers-frequent...nt-shells.html
 
Old 02-24-2010, 03:47 PM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,580
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
There are open source versions of ksh. You can run it on Linux (we do). There was an older ksh for OSS called pdksh that acted somewhat differently than the newer ksh and that may be why folks didn't like it.

There are several differences - bash has most of what ksh does and then some extra stuff. A script written to run in ksh would likely run in bash just fine. A lot of the differences deal with math, variables, arrays, functions etc... - bash just seems to have a hell of lot more of this than ksh

One thing that originally kept me from using bash over ksh was that I liked the vi style editing that ksh used by default but not bash. However, you can type "set -o vi" in bash to get that same functionality.
 
Old 02-25-2010, 11:11 AM   #4
dev_d
LQ Newbie
 
Registered: Feb 2010
Location: Tempe, Arizona
Distribution: Ubuntu
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks jlightner

@rweaver - The link which u attached is having problem while opening.
 
Old 02-25-2010, 12:02 PM   #5
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Odd, it opens from my net host, work machine, and home machine. Not sure what problem it might be having.
 
Old 02-25-2010, 01:33 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,580
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
Quote:
Originally Posted by rweaver View Post
Odd, it opens from my net host, work machine, and home machine. Not sure what problem it might be having.
It works for me too. Funny - I was going to provide the link and others but they are 7 years old or more. I have to believe there have been other enhancements to both ksh and bash since then.
 
Old 02-26-2010, 09:08 AM   #7
dev_d
LQ Newbie
 
Registered: Feb 2010
Location: Tempe, Arizona
Distribution: Ubuntu
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks neways jlightner
 
Old 02-26-2010, 09:44 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
More recent overviews of shells at KahKahKah and Wikipedia and a detailed comparison at Wikipedia.
 
Old 02-26-2010, 10:19 AM   #9
GazL
Senior Member
 
Registered: May 2008
Posts: 4,091
Blog Entries: 1

Rep: Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541Reputation: 1541
Quote:
Originally Posted by jlightner View Post
A script written to run in ksh would likely run in bash just fine. A lot of the differences deal with math, variables, arrays, functions etc... - bash just seems to have a hell of lot more of this than ksh
bash isn't always the winner. ksh has some nice useful variable typing that bash doesn't.
Code:
$ typeset -l lowercase_only
$ lowercase_only="WiBbLe"
$ echo $lowercase_only   
wibble
It's much easier than
Code:
lowercase_only=$(echo "WiBbLe" | tr "[:upper:]" "[:lower:]")
... and you don't have to keep reapplying the translation to ensure the value is lowercase should the value ever be changed. Very Useful for when dealing with user input.


I also prefer the ksh math syntax of
Code:
let a=b+c
rather than bash's more unwieldy;
Code:
a=$(( b+c ))
... but that's just a minor style thing.


The biggest difference that tends to catch people out though is this one...

ksh:
Code:
$ echo wibble | read variable
$ echo $variable
wibble
$
bash:
Code:
bash-3.1$ echo wibble | read variable
bash-3.1$ echo $variable

bash-3.1$
... Oi! bash!... where'd my variable go?
What makes this one particularly bad is that the bash code looks like it ought to work. It's only when you understand the underlying semantics of how bash deals with pipelines that you realise why it doesn't.

Because bash runs a pipeline in a sub-shell, you actually have to do it like this
Code:
read variable < <(echo wibble)
echo $variable

I prefer ksh in many ways, but I'm sure part of that is because it's what I'm used to being an old timer.

Last edited by GazL; 02-26-2010 at 10:22 AM.
 
Old 02-26-2010, 01:13 PM   #10
mesiol
Member
 
Registered: Nov 2008
Location: Lower Saxony, Germany
Distribution: CentOS, RHEL, Solaris 10, AIX, HP-UX
Posts: 731

Rep: Reputation: 137Reputation: 137
Hi,

one reason for using ksh for scripting is, this shell is available on nearly all existing flavours of *nix. Bash is not installed by default on all *nix.
 
Old 02-26-2010, 03:00 PM   #11
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,580
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
Don't get me wrong. I've liked ksh ever since I first saw back in the early 90s. I was just saying there's a hell of a lot added to bash that doesn't exist in ksh or the posix sh.

I also agree that ksh is available on multiple platforms by default but bash would have to be specifically added. On the flip side though, most Linux distros come with bash and you have to add ksh if you want it.

For most of my scripting what I learned with ksh is sufficient so I do it that way (most of my math I do by piping to bc -l which works in both ksh and bash). However, I've seen enough other examples to let me know that bash can do some fairly sophisticated things of its own that ksh doesn't. The examples show indicate different ways of doing things in bash than ksh but didn't show anything that could be done in ksh that can't be done in bash in some way.
 
Old 02-26-2010, 05:17 PM   #12
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by mesiol View Post
Hi,

one reason for using ksh for scripting is, this shell is available on nearly all existing flavours of *nix. Bash is not installed by default on all *nix.
but ksh is not installed by default on all linux at least..

Me I find bash's way of handling arrays easier and also the SIGCHILD signal (not sure if its there in KSH) is also important.

Last edited by konsolebox; 02-26-2010 at 05:28 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash vs ksh Nickbrandson Linux - Newbie 7 04-23-2008 07:40 PM
the difference ksh wanghao Linux - Server 2 03-19-2008 07:18 AM
shell versus bash, whats the difference? mayaabboud Linux - Newbie 5 12-21-2007 07:21 AM
bash or ksh noir911 *BSD 5 05-10-2007 12:08 PM
Whats the difference Linux Console and BASH Shell glenn69 Linux - Newbie 2 08-31-2003 04:19 PM


All times are GMT -5. The time now is 06:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration