- Notifications
You must be signed in to change notification settings - Fork34
ksh 93u+m: KornShell lives! | Latest release:https://github.com/ksh93/ksh/releases
License
ksh93/ksh
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Welcome to the repository where the KornShell is under active development.This is where we develop bugfixes and new features for the shell, and whereusers can download the latest releases or the current development version insource code form.The project started off from last stable release (93u+ 2012-08-01) ofksh93,formerly developed by AT&T Software Technology (AST).The sources in this repository were forked from theGitHubAST repositorywhich is no longer under active development.
For user-visible fixes, seeNEWSand click on commit messages for full details.For all fixes, seethe commit log.To see what's left to fix, seethe issue tracker.
- Feature development for future releases happens on the dev branch.The numbered release branch(es) are feature-frozen and get bugfixesand maintenance only, usually cherry-picked from the dev branch.
- No major rewrites. No refactoring code that is not fully understood.Even gradual and careful development may culminate in profound changes.Bit rot is prevented by cleaning up unused and obsolete code.
- Maintain documented behaviour. Changes required for compliance with thePOSIX shell language standardare implemented for the
posix
mode only to avoid breaking legacy scripts. - No 100% bug compatibility. Broken and undocumented behaviour gets fixed.
- No bureaucracy, no formalities. Just fix it, or report it: create issues,send pull requests. Every interested party is invited to contribute.
- To help increase everyone's understanding of this code base, fixes andsignificant changes should be fully documented in commit messages.Each commit should be a complete, self-contained and self-documentingchange, including updates to documentation and regression tests whereapplicable. Pull requests are therefore squashed into a single commit.
- Code style varies somewhat in this historic code base.Your changes should match the style of the code surrounding them.Indent with tabs, assuming an 8-space tab width.Opening braces are on a line of their own, at the same indentation levelas their corresponding closing brace.Comments always use
/*
...*/
. - Good judgment may override this policy.
Between 2017 and 2020 there was an ultimately unsuccessfulattemptto breathe new life into the KornShell by extensively refactoring the lastunstable AST beta version (93v-).While that ksh2020 effort is now abandoned and still has many critical bugs,it also had a lot of bugs fixed. More importantly, the AST issue trackernow contains a lot of documentation on how to fix those bugs, which madeit possible to backport many of them to the last stable release instead.This ksh 93u+m reboot now incorporates many of these bugfixes,plus patches fromOpenSUSE,Red Hat,andSolaris,as well as many new fixes from the community(1,2).Though there are manybugs left to fix,we are confident at this point that 93u+m is already the least buggy versionof ksh93 ever released.As of late 2021, distributions such as Debian and Slackware have begunto package it as their default version of ksh93.
You can download arelease tarball,or clone the current code from your preferred branch.New features for the future release series are developed on thedev
branch.Stable releases are currently based on the1.0
branch.
KornShell 93u+m is currently known to build and run on:
- Android/Termux
- Cygwin
- DragonFly BSD
- FreeBSD
- Haiku
- illumos distributions (e.g., OmniOS)
- Linux: all distributions with glibc or musl libc
- macOS
- NetBSD
- OpenBSD
- QNX Neutrino (6.5.0)
- Solaris
Systems that may work, but that we have not been able to test lately, include:
- AIX
- HP-UX
- UnixWare
KornShell 93u+m supports systems that use the ASCII character set as thelowest common denominator. This includes Linux on IBM zSeries, but not z/OS.Support for the EBCDIC character set has been removed, as we do not haveaccess to a mainframe with z/OS to test and maintain it.
The build system requires only a basic POSIX-compatible shell, utilities andcompiler environment. Thecc
,ar
andgetconf
commands are needed atbuild time. Thetput
andgetconf
commands are used at runtime ifavailable (for multiline editing and to complete thegetconf
built-in,respectively). Not all systems come with all of these preinstalled. Here aresystem-specific instructions for making them available:
- Android/Termux:install dependencies using
pkg install
.- Build dependencies:
clang
,binutils
,getconf
- Runtime dependencies (optional):
ncurses-utils
,getconf
- Build dependencies:
- macOS:install the Xcode Command Line Tools:
xcode-select --install
- (to be completed)
To build ksh with a custom configuration of features, editsrc/cmd/ksh93/SHOPT.sh
.
On systems such as NetBSD and OpenBSD, where/bin/ksh
is not ksh93 and thepreinstalled/etc/ksh.kshrc
profile script is incompatible with ksh93, you'llwant to disableSHOPT_SYSRC
to avoid loading it on startup -- unless you canedit it to make it compatible with ksh93. This generally involves differencesin the declaration and usage of local variables in functions.
Thencd
to the top directory and run:
bin/package make
To suppress compiler output, usequiet make
instead ofmake
.
In some non-POSIX shells you might need to prependsh
to all calls tobin/package
.
Parallel building is supported by appending-j
followed by thedesired maximum number of concurrent jobs, e.g.,bin/package make -j4
.This speeds up building on systems with more than one CPU core.(Typebin/package host cpu
to find out how many CPU cores your system has.)
The compiled binaries are stored in thearch
directory, in a subdirectorythat corresponds to your architecture. The commandbin/package host type
outputs the name of this subdirectory.
Dynamically linked binaries, if supported for your system, are stored indyn/bin
anddyn/lib
subdirectories of your architecture directory.If built, they are built in addition to the statically linked versions.ExportAST_NO_DYLIB
to deactivate building dynamically linked versions.
If you have trouble or want to tune the binaries, you may pass additionalcompiler and linker flags. It is usually best to export these as environmentvariablesbefore runningbin/package
as they could change the name ofthe build subdirectory of thearch
directory, so exporting them is aconvenient way to keep them consistent between build and test commands.Note that this system usesCCFLAGS
instead of the usualCFLAGS
.An example that makes Solaris Studio cc produce a 64-bit binary:
export CCFLAGS="-m64 -O" LDFLAGS="-m64"bin/package make
Alternatively you can append these to the command, and they will only beused for that command. You can also specify an alternative shell in whichto run the build scripts this way. For example:
bin/package make SHELL=/bin/bash CCFLAGS="-O2 -I/opt/local/include" LDFLAGS="-L/opt/local/lib"
Note: Do not add compiler flags that cause the compiler to emit terminalescape codes, such as-fdiagnostics-color=always
; this will cause thebuild to fail as the probing code greps compiler diagnostics. Additionally,do not add the-ffast-math
compiler flag; arithmetic bugs will occur whenusing that flag.
For more information run
bin/package help
Many other commands in this repo self-document via the--help
,--man
and--html
options; those that do have no separate manual page.
After compiling, you can run the regression tests.To run the default test sets for ksh and the build system, use:
bin/package test
For ksh, use theshtests
command directly to control the regression test runs.Start by reading the information printed by:
bin/shtests --man
To hand-test ksh (as well as the utilities and the autoloadable functionsthat come with it) without installing, run:
bin/package use
Usage:bin/package install
destination_directory [command ... ]
Any command from thearch
directory can be installed. If nocommand isspecified,ksh
andshcomp
are assumed.
Thedestination_directory is created if it does not exist. Commands areinstalled in itsbin
subdirectory and each command's manual page, ifavailable, is installed inshare/man
.
Destination directories with whitespace or shell pattern characters in theirpathnames are not yet supported.
If a dynamically linked version of ksh and associated commands has beenbuilt, then theinstall
subcommand will prefer that: commands, dynamiclibraries and associated header files will be installed then. To install thestatically linked version instead (and skip the header files), either deletethedyn
subdirectory, or exportAST_NO_DYLIB=y
before building to preventit from being created in the first place.
The following is the official AT&T description from 1993 that came with theast-open distribution. The text is original, but hyperlinks were added here.
KSH-93 is the most recent version of the KornShell Language described in"The KornShell Command and Programming Language," by Morris Bolsky and DavidKorn of AT&T Bell Laboratories, ISBN 0-13-182700-6. The KornShell is a shellprogramming language, which is upward compatible with "sh" (the BourneShell), and is intended to conform to the IEEE P1003.2/ISO 9945.2Shell and Utilities standard.KSH-93 provides an enhanced programming environment in addition to the majorcommand-entry features of the BSD shell "csh". With KSH-93, medium-sizedprogramming tasks can be performed at shell-level without a significant lossin performance. In addition, "sh" scripts can be run on KSH-93 withoutmodification.
The code should conform to theIEEE POSIX 1003.1 standardand to the proposed ANSI C standard so that it should be portable to allsuch systems. Like the previous version, KSH-88, it is designed to accepteight bit character sets transparently, thereby making it internationallycompatible. It can support multi-byte characters sets with somecharacteristics of the character set given at run time.
KSH-93 provides the following features, many of which were also inherent inKSH-88:
- Enhanced Command Re-entry Capability: The KSH-93 history function recordscommands entered at any shell level and stores them, up to auser-specified limit, even after you log off. This allows you to re-enterlong commands with a few keystrokes - even those commands you enteredyesterday. The history file allows for eight bit characters in commandsand supports essentially unlimited size histories.
- In-line Editing: In "sh", the only way to fix mistyped commands is tobackspace or retype the line. KSH-93 allows you to edit a command lineusing a choice of EMACS-TC or "vi" functions. You can use the in-lineeditors to complete filenames as you type them. You may also use thisediting feature when entering command lines from your history file. A usercan capture keystrokes and rebind keys to customize the editing interface.
- Extended I/O Capabilities: KSH-93 provides several I/O capabilities notavailable in "sh", including the ability to:
- specify a file descriptor for input and output
- start up and run co-processes
- produce a prompt at the terminal before a read
- easily format and interpret responses to a menu
- echo lines exactly as output without escape processing
- format output using printf formats.
- read and echo lines ending in "\".
- Improved performance: KSH-93 executes many scripts faster than the SystemV Bourne shell. A major reason for this is that many of the standardutilities are built-in. To reduce the time to initiate a command, KSH-93allows commands to be added as built-ins at run time on systems thatsupport dynamic loading such as System V Release 4.
- Arithmetic: KSH-93 allows you to do integer arithmetic in any base fromtwo to sixty-four. You can also do double precision floating pointarithmetic. Almost the complete set of C language operators are availablewith the same syntax and precedence. Arithmetic expressions can be used toas an argument expansion or as a separate command. In addition, there is anarithmetic for command that works like the for statement in C.
- Arrays: KSH-93 supports both indexed and associative arrays. The subscriptfor an indexed array is an arithmetic expression, whereas, the subscriptfor an associative array is a string.
- Shell Functions and Aliases: Two mechanisms - functions and aliases - canbe used to assign a user-selected identifier to an existing command orshell script. Functions allow local variables and provide scoping forexception handling. Functions can be searched for and loaded on firstreference the way scripts are.
- Substring Capabilities: KSH-93 allows you to create a substring of anygiven string either by specifying the starting offset and length, or bystripping off leading or trailing substrings during parametersubstitution. You can also specify attributes, such as upper and lowercase, field width, and justification to shell variables.
- More pattern matching capabilities: KSH-93 allows you to specify extendedregular expressions for file and string matches.
- KSH-93 uses a hierarchical name space for variables. Compound variables canbe defined and variables can be passed by reference. In addition, eachvariable can have one or more disciplines associated with it to interceptassignments and references.
- Improved debugging: KSH-93 can generate line numbers on execution traces.Also, I/O redirections are now traced. There is a DEBUG trap that getsevaluated before each command so that errors can be localized.
- Job Control: On systems that support job control, including System VRelease 4, KSH-93 provides a job-control mechanism almost identical tothat of the BSD "csh", version 4.1. This feature allows you to stop andrestart programs, and to move programs between the foreground and thebackground.
- Added security: KSH-93 can execute scripts which do not have readpermission and scripts which have the setuid and/or setgid set wheninvoked by name, rather than as an argument to the shell. It is possibleto log or control the execution of setuid and/or setgid scripts. Thenoclobber option prevents you from accidentally erasing a file byredirecting to an existing file.
- KSH-93 can be extended by adding built-in commands at run time. Inaddition, KSH-93 can be used as a library that can be embedded into anapplication to allow scripting.
Documentation for KSH-93 consists of an "Introduction to KSH-93","Compatibility with the Bourne Shell" and a manual page and a README file.In addition, the "New KornShell Command and Programming Language" book isavailable from Prentice Hall.
About
ksh 93u+m: KornShell lives! | Latest release:https://github.com/ksh93/ksh/releases
Topics
Resources
License
Stars
Watchers
Forks
Languages
- C70.4%
- Shell19.9%
- Roff8.4%
- Other1.3%