Graphical Desktop Korn Shell

The Graphical Desktop Korn Shell (DtKsh) is a featured part of the Common Desktop Environment (CDE). DtKsh provides a consistent and reliable graphical Motif shell language that is supported on all CDE-compliant systems.

Portability and pervasiveness are two important characteristics to consider when you are developing code. Using a programming language with a well-defined and stable application programming interface (API) answers the need for portability. A programming language with a large, established installed base provides pervasiveness. Although Perl, Tcl/Tk, Common Gateway Interface (CGI) and Java have large installed bases, they are not suited for some projects. The reason for this is their inconsistent installation base due to the lack of a well-defined or rapidly changing API.

The Desktop Korn Shell (DtKsh) that comes with the Common Desktop Environment (CDE) is built on the ksh93 standard with X, Xt, Motif, ToolTalk and CDE built-in APIs. Unlike Perl and Tcl/Tk, major vendors have built and supported DtKsh through the CDE initiative. Using DtKsh, desktop programmers can develop and/or prototype plug-and-play Graphical User Interface (GUI) applications that are compatible on all CDE-compliant systems without compilation. Although DtKsh applications are interpreted for portability, they can easily be migrated to Motif in C for performance.

Tcl/Tk can be ported to C with the aid of special Tcl/Tk libraries; however, programmers are as disadvantaged with the C Tcl/Tk libraries as they are with the Tcl/Tk shell, because of a not-so-standard application programming interface. DtKsh, unlike Tcl/Tk, provides a well-established API set where the programmer's knowledge transcends from C to shell programming.

DtKsh Benefits

In AIX, /bin/ksh is an XPG4-compliant version of ksh88. CDE's /usr/dt/bin/dtksh on AIX is based on the newer ksh93 standard. ksh93 now includes floating-point mathematics, associative arrays, new string operations, hierarchical variables, reference variables, developer-extendable APIs using attached shared libraries and character class patterns.

Floating-point mathematics: Korn Shell variables can be cast, or defined, to various aggregate data types. Floating-point mathematics is a new feature in the Korn Shell that enables the assignment and operation of decimal values. The following example defines the floating-point variable PI, then assigns to it the decimal value of 3.14159.

typeset -F PI # define "PI" as a float
PI = 3.14159

Associative arrays: Instead of using positive integer indices, associative arrays allow elements of an array to be addressed using alphanumeric strings. The following example shows SYSINFO as an array containing information about an operating system. The associative SYSINFO array can be indexed with the alphanumeric string of "os" to find the string value of AIX.

typeset -A SYSINFO # define "SYSINFO" as an
# associative array
New string operations: Six new string operations were introduced in ksh93. These new operations provide substringing and substitution of a string pattern with an alternate. Substringing permits extraction of a smaller string, given an offset indicating where to begin and possibly its length.
  • A substring of a larger string can be extracted by length at a given starting point, or a substring can be taken by starting at the offset within the larger string and stopping at the end of the string. The following shows a substring of a given length:


  • A substring of no particular length can be taken by just providing the offset.

    String substitution of a character pattern can be performed for the first occurrence, a repeated occurrence, at the beginning of the string (prefix) or at the end of the string (suffix).

  • Substitute the first occurrence of a pattern with an alternate string:


  • Substitute all occurrences of a pattern with an alternate string:


  • Substitute the pattern prefix with the alternate string:


  • Substitute the pattern suffix with the alternate string:


Hierarchical variables: Hierarchical variables, or compound names, enable C structure-like aggregate data types. This allows Korn Shell to store information in variables in an associative fashion. For example, if we had a box with a width of 80 and a height of 24, then we could store all that information in one hierarchical variable instead of separate and disjointed variables of storage. Each element of the compound name must be used before setting sub-members.
BOX= # declare before assigning sub-members
Reference variables: Referencing allows a variable to point to the same value as another variable; both variables reference the same value as shown below:
# name reference
typeset -n FOO=BAR
FOO="Hello World"
# print "Hello World"
print ${BAR}
Desktop built-in commands: Korn Shell provides some standard X, Xt, Motif, POSIX internationalization and CDE C language APIs directly built into the shell. Direct access to these APIs from the shell provides a significant runtime performance improvement for DtKsh shell applications. Using the standard X and Motif APIs, with some semantic changes to the source, makes it possible for DtKsh shell scripts to be migrated to C and compiled.

POSIX internationalization: Korn Shell provides the shell equivalent of the C language POSIX internationalization APIs catopen and catgets. The internationalization APIs allow the shell program to change its message catalog depending on its language. Internationalized shell scripts enable multilingual support.

Character class patterns: Regular expressions in the shell are enhanced by predefining a set of character class patterns. Now we can easily match certain classes of characters by using the [[:class:]] notation where class can be specified as alnu, alpha, cntrl, digit, graph, lower, upper, print, punct, space and xdigit.

# only print files that
# begin in upper case
print  [[:upper:]]*
# old way
print [A-Z]*

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

Upcoming Webinar
8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
11am CDT, April 29th
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot