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

Use zsh to emulate ksh UNIX
OS X comes with zsh but not ksh. zsh can be made to emulate ksh much like bash emulates sh. If you look in /bin, you will find tcsh and csh are hard linked to the same (tcsh) file, likewise bash and sh. To get zsh to deal with ksh shell scripts, you can issue:
  sudo ln /bin/zsh /bin/ksh
This must be a hard link to function correctly. The zsh page suggests a soft link, which on other UNIX systems seems to work, but Darwin apparently requires a hard link for it to function properly. Like bash, zsh "senses" how you invoke it (ksh vs. zsh; sh vs. bash) and sets defaults for the shell session accordingly.

You can also install ksh93 via fink unstable and then hard link it in the same way. Using zsh, however, is much more straightforward.
    •    
  • Currently 2.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[11,275 views]  

Use zsh to emulate ksh | 13 comments | Create New Account
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 | # ]
Use zsh to emulate ksh
Authored by: mervTormel on Jun 10, '03 11:25:07AM

the shells are not hard linked:

$ ls -i1 /bin/*sh* | sort
663179 /bin/bash.205a.disabled
743103 /bin/bash
817572 /bin/sh
817578 /bin/zsh
817587 /bin/zsh-4.0.4
817593 /bin/tcsh
817605 /bin/csh



[ Reply to This | # ]
Use zsh to emulate ksh
Authored by: wgscott on Jun 10, '03 11:42:05AM

This is odd:

% ls -i1 /bin/*sh*
2609239 /bin/bash*
2609265 /bin/csh*
2609234 /bin/ksh*
2609252 /bin/sh*
2609250 /bin/tcsh*
2609234 /bin/zsh*
2609235 /bin/zsh-4.0.4*

BUT they are the same size. So instead of hard linking, I guess they copied them?

% ls -lF /bin/*sh*
-rwxr-xr-x 1 root wheel 540884 Mar 22 19:29 /bin/bash*
-r-xr-xr-x 1 root wheel 315136 Mar 22 19:29 /bin/csh*
-rwxr-xr-x 2 root wheel 828780 Mar 22 19:29 /bin/ksh*
-r-xr-xr-x 1 root wheel 540884 Mar 22 19:29 /bin/sh*
-r-xr-xr-x 1 root wheel 315136 Mar 22 19:29 /bin/tcsh*
-rwxr-xr-x 2 root wheel 828780 Mar 22 19:29 /bin/zsh*
-rwxr-xr-x 1 root wheel 828780 Mar 22 19:29 /bin/zsh-4.0.4*
%




[ Reply to This | # ]
Use zsh to emulate ksh
Authored by: wgscott on Jun 10, '03 11:46:45AM

The main point was that symbolic linking, as suggested on the zsh page, will cause subtle problems that for me only showed up in the context of a program I have that relies on embedded ksh scripts.

The problem went away when I hard linked it. It would have also gone away if I had cp /bin/zsh /bin/ksh



[ Reply to This | # ]
Use zsh to emulate ksh
Authored by: mac_guy on Jun 10, '03 11:34:39AM

If you want the Korn Shell, download it from its homepage then install it by moving the file to shells directory. I did.



[ Reply to This | # ]
Use zsh to emulate ksh
Authored by: wgscott on Jun 10, '03 11:44:21AM

you can also install it via fink.

This was simply to point out you don't have to.

If you want csh you can install that instead of having tcsh invoked as csh.

If you want sh you can install the bourne shell instead of having it invoked as bash.

The point in each case is that you don't have to .



[ Reply to This | # ]
hint is now obsolete
Authored by: wgscott on Feb 04, '11 11:57:28AM

OS X 10.5 and 10.6 have /bin/ksh, so there is no longer a need for this.



[ Reply to This | # ]