Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use zsh to emulate ksh' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use zsh to emulate ksh
Authored by: dave@mmu on Jun 10, '03 10:43:52AM

what the bloomin' eck is all that about?

---
Dave L



[ Reply to This | # ]
Background
Authored by: gidds on Jun 10, '03 11:19:39AM
We're talking about shells - command line interpreters.  When you fire up a Terminal window, it runs a program to read in your commands and execute them; this is called a shell.

There are several different shells, each with slightly different features (automatic completion, job control, filename expansion, programming features, &c.).  If you're interested in the history: the first Unix shell was called the Bourne shell, and was simply called sh (in the Unix tradition of keeping things short).  It had only very basic features, so there have been several more shells since, each with new stuff.  csh (the C shell) added several programming features, a little like the C programming language; tcsh (the T shell) added lots of other features on top of that.  ksh (the Korn shell, written by a guy called Korn) started with the Bourne shell, and added lots of stuff in a similar way.  zsh adds lots more features on top of that.  And finally, the other popular shell is bash (the Bourne Again shell), which started off as the GNU project's rewrite of the Bourne shell, but has added lots of features similar to the others.

The problem is that all of these shells have many similar features, but all implemented in slightly different ways and requiring slightly different syntax.  So when writing very complex scripts, you either need to be very careful to use lowest-common-denominator features, or you need to specify which shell to use.

Mac OS X comes with sh, bash (the default), and zsh.  Unfortunately for folks who like ksh, that's proprietary, so there's no Mac OS X version.  However, because zsh was based on it, you can tell zsh to pretend to be ksh, which is what this hint is about.

Personally, I suggest people go the whole hog and use zsh for itself.  It's similar enough to ksh that most stuff runs anyway, and people will feel at home, but it's got some really neat new features.  For example, spelling correction and completion, command-line editing, shell functions, history, and my favourite: powerful recursive filename completion, which completely removes the need for a separate find command, and lets you do some really neat stuff very easily.

---

Andy/

[ Reply to This | # ]

Background
Authored by: wgscott on Jun 10, '03 11:33:42AM

The reason for linking it to ksh is that you might have scripts that run on other unix platforms written to invoke ksh. This is the case for some software I was recently compiling for OS X. So you can either hunt down and edit all of these files and debug them to ensure that they run uder zsh, and then instruct all other users on how to do it, or you can issue a 1 line command.

zsh functions differently when emulating ksh than it does by default, so you have to tell it to emulate ksh for it to work right on ksh scripts. Linking and invoking "tells it" to do so automatically.



[ Reply to This | # ]
Background
Authored by: TedCD on Jun 10, '03 08:38:31PM

I've been using a .zshrc file with the command "emulate ksh" in it.

Would that have the same effect?

Ted

---
Ted



[ Reply to This | # ]
Nope
Authored by: SeanAhern on Jun 11, '03 07:05:03PM

Not if you have to run two different scripts, one which starts with

#!/bin/ksh

and another which says

#!/bin/zsh

---
-Sean



[ Reply to This | # ]
Background
Authored by: dave@mmu on Jun 11, '03 04:30:39AM

Andy, cheers for that! The mud is clearing slightly. So basically, the higher up in the versions of shell, the more / different commands the shell will run as an interpreting environment? Cool.. I can see how that would be useful.
Dave

---
Dave L



[ Reply to This | # ]
Background
Authored by: jyncroft on Jun 13, '03 10:24:35AM

Andy writes -
> Mac OS X comes with sh, bash (the default), and zsh.
> Unfortunately for folks who like ksh, that's proprietary,
> so there's no Mac OS X version.

I thought the default shell was tcsh?

- Jennifer (been using zsh so long I forget what is 'default')



[ Reply to This | # ]