ksh keeps up

By Cameron Laird and Kathryn Soraiz, Unix Insider |  Development Add a new comment

You're a shell programmer, right? Do you know how far that can take you?


If you use ksh93, you can travel roughly as far as you could with any other scripting language.


You already know it

Most Unix workers have done at least simple command-line scripting with login shells such as sh, bash, tcsh, and so on. Perhaps you've needed the names of the 10 files in a particular directory that were most recently changed, and you wrote:


      ls -1td $DIRECTORY | head -10
   


If you know that much about programming the shell, then you're ready to do complicated arithmetic, network applications, and even GUIs. That's the promise that ksh93 fulfills.


ksh is the Korn shell, named after AT&T Labs researcher David Korn. Korn has been working on ksh for almost 20 years. ksh is upward-compatible with the Bourne shell (sh), it has essentially all the capabilities of other popular login shells, it was a standard for SysVr4 Unix, and it was the reference for the POSIX and ISO shell definitions. It's also faster than other shells, sometimes as much as by an order of magnitude, and it has functionality that makes it a full-fledged language, on a par with Perl, Tcl, and other newcomer languages.


What was the holdup?

So why aren't you already using ksh for everything you do? Probably not for technical reasons. ksh has always been owned by AT&T and other companies (various combinations of Lucent and Novell, mostly). Its license was onerous, compared with those of Perl, Tcl, and Bash. This hindered its adoption in many cases.


Last year, however, Korn succeeded in opening up the source code, and now ksh93 is available in both source and binary forms under a liberal AT&T license. This promotes Korn's positioning of KornShell (the language that ksh93 implements) as a peer of Perl, Python, and so on. "We don't write anything in Perl anymore, because [ksh93] has all the functionality built-in," Korn claims.


That's strictly true only for a restricted meaning of all, of course; there's no ksh equivalent to CPAN, which supplies all Perl's add-on functionality in Web service, database management, and other specific areas. ksh93 also doesn't support programming in the large with the namespaces, object orientation, and exception handling of other advanced scripting languages. However, anyone accustomed to shell programming who needs to manage networks, build GUI control panels, integrate C-coded modules, and write maintainable applications should look into ksh93. ksh is nearly unique, of course, in offering all this power from a processor that is also usable as a login shell.


Portable shell

ksh93 is freely available for essentially all Unixes, and also, with light license restrictions, for Windows and MVS. A handful of vendors support ksh93 commercially. Korn's team at AT&T plans to upgrade a future release of KornShell with a combination of object inheritance, support for binary objects, and namespaces. Also for that release, Korn writes, "Multithreading is a possibility, but less likely than the others."


Korn has even made much of the contents of his authoritative reference book on ksh available for download. Here's an example fragment, which gives an idea of ksh's syntax and functionality:


      # Set SECONDS to number of seconds since midnight.
      export SECONDS="$(date '+3600*%H+60*%M+%S')"
      # The following variables store hours and minutes.
      typeset -Z2 _h _m       # Two columns, leading zeros.
      # The following expression reformats SECONDS.
      _time='$((_h=(SECONDS/3600)%24)):$((_m=(SECONDS/60)%60))'
      # Use _time within PS1 to get the time of day.
      PS1="($_time)"'!$ '
      # Note that $_time gets replaced by above expression.
      # Expression gets evaluated when PS1 is displayed.    
   

    Add a comment

    Post a comment using one of these accounts
    Or join now
    At least 6 characters

    Note: Comment will appear soon after you have activated your account.
    Obscene/spam comments will be removed and accounts suspended.
    The information you submit is subject to our Privacy Policy and Terms of Service.

    ITworld LIVE

    DevelopmentWhite Papers & Webcasts

    White Paper

    HP NonStop SQL Fundamentals whitepaper

    This whitepaper offers a detailed look into the fundamentals of HP NonStop SQL solutions. See how this system delivers unprecedented levels of application availability with fail-safe data integrity and meets the needs of enterprises with large-scale business critical applications.

    White Paper

    Nebraska Medical Center case study

    See how the Nebraska Medical Center implemented a SQL solution to make information more readily available to streamline operations, improve patient care and facilitate medical research with an enterprise solution running on HP NonStop servers.

    White Paper

    Concepts of NonStop SQL/MX

    For DBAs and developers who are familiar with Oracle solutions and want to learn about NonStop SQL/MX, this whitepaper provides an overview of the similarities and differences between the two products-with a specific focus on implementation.

    White Paper

    6 Things Your CIO Needs to Know About Requirements

    If your organization is not predictably successful on technology projects, there is likely an issue in requirements. CIOs must take action and own requirements maturity improvement. There are 6 main things a CIO must know about requirements.

    Webcast On Demand

    User Experience Monitoring

    In this webinar, you will learn hints & tips for improving end-user response times from Forrester Research analyst, Jean-Pierre Garbani.

    Sponsor: Nimsoft

    See more White Papers | Webcasts

    Ask a question

    Ask a Question