Differences between revisions 9 and 11 (spanning 2 versions)
Revision 9 as of 2008-03-25 14:05:17
Size: 4305
Editor: p54BFD458
Comment: reindent for consistency
Revision 11 as of 2008-11-22 14:09:21
Size: 4538
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
The KornShell is a reimplementation of the BourneShell. It is downward compatible, but adds many features intented to simplify programming. Most of the features are part of PosixShell, too, and therefore are available on any PosixSystem. The KornShell is a reimplementation of the [[BourneShell|Bourne shell]]. It is downward compatible, but adds many features intented to simplify programming. Most of the features are part of [[PosixShell|POSIX shell]], too, and therefore are available on any POSIX compliant system.
Line 4: Line 4:
The BashShell also implements most of the functionality. [[Bash]] also implements most of the Korn shell's functionality.
Line 6: Line 6:
The KornShell is part of any modern (commercial) Unix system, e.g. ["Solaris"], ["AIX"], ["HP-UX"]. An OpenSource version called PdKsh ("Public Domain Korn Shell") is available e.g. for ["Linux"]. There are three primary version of the Korn shell in use today: the original (often dubbed '''ksh88'''), the successor ('''ksh93'''), and an open source version called '''pdksh''' ("Public Domain Korn Shell"). pdksh was developed before the source code for ksh93 was liberated.
Line 8: Line 8:
The successor to the KornShell is KornShell93, which adds even more features. The source for KornShell93 was recently liberated, and some GNU/Linux distributions now offer it in addition to (or instead of) PdKsh. The Korn shell (either ksh88 or ksh93, depending on the age of the system) is a standard part of any modern (commercial) Unix system, e.g. [[Solaris]], [[AIX]], [[HP-UX]]. pdksh is often available on BSD or GNU/Linux systems, and a growing number of GNU/Linux systems now offer ksh93, either instead of or in addition to pdksh.
Line 10: Line 10:
Some of the features of the Korn shell are:
Line 11: Line 12:
 * '''TypedVariables''' using the [wiki:Self:TypedefCommand typedef] command. It can be used to print strings left- or right-aligned, print integer numbers with leading zeros, or provide LocalVariables for a function  * '''TypedVariables''' using the [[TypedefCommand|typedef]] command. It can be used to print strings left- or right-aligned, print integer numbers with leading zeros, or provide LocalVariables for a function
Line 14: Line 15:
        # ksh93
Line 21: Line 23:
        parent=`basename \`dirname "${PWD}"`         parent=`basename \`dirname "${PWD}"\``
Line 42: Line 44:
 * [wiki:Self:CoProcess Co-processes], e.g. {{{bc |&}}} to start the "bc" command as a co-process. "{{{read -p}}}" and "{{{print -p}}}" are used to read from or write to the co-process. Other shells (e.g. ["BASH"]) require the user to use e.g. NamedPipes (FiFos) for that purpose  * [[CoProcess|Co-processes]], e.g. {{{bc |&}}} to start the "bc" command as a co-process. "{{{read -p}}}" and "{{{print -p}}}" are used to read from or write to the co-process. Other shells (e.g. [[BASH]]) require the user to use e.g. NamedPipes (FiFos) for that purpose
Line 44: Line 46:
 * '''[wiki:Self:SelectComand select]''' command for easy menus. {{{select}}} is used like {{{for}}}, but prints an simple interactive menu where a user can select one out of several choices.
 * '''KornShellFunctions''' are similar to traditional BourneShell functions, but can have local variables, local argument handling using [wiki:Self:GetoptsCommand getopts], and local [wiki:Self:TrapCommand traps]
 * Built-in [wiki:Self:TestOperator [[] ("test") with improved quoting behaviour and more conditional operators than the OldTestOperator
 * CommandLineEditing with [wiki:Self:ViEditor vi] or [wiki:Self:EmacsEditor emacs] command sequences
 * '''[[SelectComand|select]]''' command for easy menus. {{{select}}} is used like {{{for}}}, but prints an simple interactive menu where a user can select one out of several choices.
 * '''KornShellFunctions''' are similar to traditional BourneShell functions, but can have local variables, local argument handling using [[GetoptsCommand|getopts]], and local [[TrapCommand|traps]]
 * Built-in [[TestOperator|[[]] ("test") with improved quoting behaviour and more conditional operators than the OldTestOperator
 * CommandLineEditing with [[ViEditor|vi]] or [[EmacsEditor|emacs]] command sequences
Line 50: Line 52:
 * Earlier versions of the Bourne shell don't know yet signal names for the [wiki:Self:TrapCommand trap] command, e.g. {{{trap 'rm temp' EXIT}}} instead of {{{trap 'rm temp' 0}}}  * Earlier versions of the Bourne shell don't know yet signal names for the [[TrapCommand|trap]] command, e.g. {{{trap 'rm temp' EXIT}}} instead of {{{trap 'rm temp' 0}}}
Line 59: Line 61:
 * some of the [wiki:Self:TypedefCommand typedef] options  * some of the [[TypedefCommand|typedef]] options

Korn Shell

The KornShell is a reimplementation of the Bourne shell. It is downward compatible, but adds many features intented to simplify programming. Most of the features are part of POSIX shell, too, and therefore are available on any POSIX compliant system.

Bash also implements most of the Korn shell's functionality.

There are three primary version of the Korn shell in use today: the original (often dubbed ksh88), the successor (ksh93), and an open source version called pdksh ("Public Domain Korn Shell"). pdksh was developed before the source code for ksh93 was liberated.

The Korn shell (either ksh88 or ksh93, depending on the age of the system) is a standard part of any modern (commercial) Unix system, e.g. Solaris, AIX, HP-UX. pdksh is often available on BSD or GNU/Linux systems, and a growing number of GNU/Linux systems now offer ksh93, either instead of or in addition to pdksh.

Some of the features of the Korn shell are:

        # ksh93
        for ((i=0; i<10; ++i)); do
            print $i
        done

        parent=`basename \`dirname "${PWD}"\``
  • with its KornShell counterpart:

        parent=$(basename $(dirname "${PWD}"))
  • Powerful PatternMatching (for filename generation and for usage in case and [[ ... ]], e.g.:

        case ${url} in
            http://*) print a browser can handle that;;
                   *) print maybe a browser can handle that, too;;
        esac

        if [[ ${pathname} == /* ]]; then
            print path is absolute;
        fi
  • ParameterSubstitution like ${var%pattern}, ${var%%pattern} to remove (last/largest) pattern from the end of variable var, and ${var#pattern}, ${var##pattern} to remove (first/largest) pattern from the front of the variable.

  • Co-processes, e.g. bc |& to start the "bc" command as a co-process. "read -p" and "print -p" are used to read from or write to the co-process. Other shells (e.g. BASH) require the user to use e.g. NamedPipes (FiFos) for that purpose

  • built-in print command. This doesn't sound like a big innovation, but it allows for reliably printing arbitrary characters. Most important uses are "print -n --" to print without trailing NewLine character, and "print -r --" to print arbitrary strings, possibly including EscapeSequences or a BackSlash character.

  • select command for easy menus. select is used like for, but prints an simple interactive menu where a user can select one out of several choices.

  • KornShellFunctions are similar to traditional BourneShell functions, but can have local variables, local argument handling using getopts, and local traps

  • Built-in [[ ("test") with improved quoting behaviour and more conditional operators than the OldTestOperator

  • CommandLineEditing with vi or emacs command sequences

Other, smaller improvements over the BourneShell include

  • Earlier versions of the Bourne shell don't know yet signal names for the trap command, e.g. trap 'rm temp' EXIT instead of trap 'rm temp' 0

  • TildeSubstitution, ~ is replaced with the user's HomeDirectory, ~_user_ is replaced with the HomeDirectory of the user _user_, e.g. echo ~root

Most of the features of the KornShell are available in the BashShell, too. The following features are not found in the BashShell:

  • co-processes (process |&)

  • built-in "print" command
  • some of the typedef options

And everyone's favorite KornShell feature that's not in Bash:

  • The last command in a pipe is executed in the current shell instead of a subshell. So the following works the way a naive user would expect:
    •   i=0
        ls -l | while read; do
          ((++i))
        done
        echo "$i lines"

KornShell (last edited 2022-06-20 20:47:27 by emanuele6)