ksh Command Purpose Invokes the Korn shell. Syntax ksh [ -i ] [ { + | - } { a e f h k m n t u v x } -o Option ... ] [ -c String | -s | -r | File [ Parameter ] ] Note: Preceding a flag with + (plus) rather than - (minus) turns off the flag. Description The Korn shell is an interactive command interpreter and a com- mand programming language. The shell carries out commands either interactively from a terminal keyboard or from a file. The ksh command invokes the Korn shell. The Korn shell is backwardly compatible with the Bourne shell (invoked with the bsh command) and contains most of the Bourne shell features as well as several of the best features of the C shell. When invoked, single-byte versions of the login shell determine whether the environment is single- or multibyte (as defined by the LANG environment variable in the /etc/environment file). If the environment is multibyte, the shell invokes its multibyte version. If the environment is single-byte, the shell continues to execute its single-byte version. To run a multibyte version of the login shell in a single-byte environment, you must invoke the shell by using the full path name of its multibyte version. This version is located in the /etc/passwd file (see the chuser command for information about changing this value). An alternative option is to change the value of the LANG environment variable in the single-byte version of your login shell and re-invoke the shell. Flags -a Exports automatically all subsequent parameters that are de- fined. -c String Causes the Korn shell to read commands from the String variable. This flag cannot be used with the -s flag or with the File[Parameter] parameter. -e Executes the ERR trap, if set, and exits if a command has a nonzero exit status. This mode is disabled while reading pro- files. -f Disables file name substitution. -h Designates each command as a tracked alias when first encoun- tered. -i Indicates that the shell is interactive. An interactive shell is also indicated if shell input and output are attached to a terminal (as determined by the ioctl subroutine). In this case, the TERM environment variable is ignored (so that the kill 0 command does not kill an interactive shell) and the INTR signal is caught and ignored (so that a wait state can be interrupted). In all cases, the QUIT signal is ignored by the shell. -k Places all parameter assignment arguments in the environment for a command, not just those arguments that precede the command name. -m Runs background jobs in a separate process and prints a line upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this flag is turned on automatically for interactive shells. -n Reads commands and checks them for syntax errors, but does not execute them. This flag is ignored for interactive shells. - o Option Prints current option settings if you do not specify an argument. You can use this flag to enable any of the follow- ing options: allexport Same as the -a flag. errexit Same as the -e flag. bgnice Runs all background jobs at a lower priority. This is the default mode. emacs Enters an emacs-style inline editor for command entry. gmacs Enters a gmacs-style inline editor for command entry. ignoreeof Does not exit the shell when it encounters an end-of- file character. You must use the exit command, or override the flag and exit the shell by pressing the Ctrl-D key sequence more than 11 times. keyword Same as the -k flag. markdirs Appends a / (slash) to all directory names that are a result of filename substitution. monitor Same as the -m flag. noclobber Prevents redirection from truncating existing files. When you specify this option, use the redirection symbol >| (right caret, pipe symbol) to truncate a file. noexec Same as the -n flag. noglob Same as the -f flag. nolog Prevents function definitions from being saved in the his- tory file. nounset Same as the -u flag. privileged Same as the -p flag. verbose Same as the -v flag. trackall Same as the -h flag. vi Enters the insert mode of a vi-style inline editor for command entry. Entering escape character 033 puts the editor into the move mode. A return sends the line. viraw Processes each character as it is typed in vi mode. xtrace Same as the -x flag. You can set more than one option on a single ksh command line. -r Runs a restricted shell. With a restricted shell you cannot: - Change the current working directory - Set the value of the SHELL, ENV, or PATH variables - Specify the pathname of a command that contains a / (slash) - Redirect output of a command with > (right caret), >| (right caret, pipe symbol), <> (left caret, right caret), or >> (two right carets). -s If the -s flag is present or if no arguments remain, then the ksh command reads commands from the standard input. Shell out- put, except for the output of the special commands, is written to file descriptor 2. This parameter cannot be used with the -c flag or with File[Parameter]. -t Exits after reading and executing one command. -u Treats unset parameters as errors when substituting. -v Prints shell input lines as they are read. -x Prints commands and their arguments as they are executed. Implementation Specifics The Korn shell is the standard operating system login shell and is backwardly compatible with the Bourne shell. The ksh command has two executable versions to optimize perfor- mance. The single-byte version is located in the /usr/bin direc- tory. The multibyte version is in the /usr/mbin directory. If multibyte locales are set as the primary locales during installa- tion, the default ksh command is /usr/mbin/ksh. If other locales are chosen during installation, the ksh command is /usr/bin/ksh. See "National Language Support Overview for System Management" in AIX Version 3.2 System Management Guide: Operating System and Devices to learn about changing Korn shell versions after instal- lation. This command is part of Base Operating System (BOS) Runtime. Files /usr/bin/ksh Contains the path name to the single-byte version of the Korn shell. /usr/mbin/ksh Contains the path name to the multibyte version of the Korn shell. /tmp/sh* Contains temporary files that are created when a shell is opened. Related Information Korn Shell in AIX Version 3.2 System User's Guide: Base and Dev- ices. The profile file format. ================================================================= ================================================================= Inline Editing in the Korn Shell Normally, you type each command line from a terminal device and follow it by a new-line character (RETURN or LINE FEED). When you activate the emacs, gmacs, or vi inline editing option, you can edit the command line. The following commands enter edit modes: set -o emacs Enters emacs editing mode and initiates an emacs- style inline editor. set -o gmacs Enters emacs editing mode and initiates a gmacs- style inline editor. set -o vi Enters vi editing mode and initiates a vi-style inline editor. An editing option is automatically selected each time the VISUAL or EDITOR variable is assigned a value ending in any of these op- tion names. Note: To use the editing features, your terminal must accept RE- TURN as a carriage return without line feed. A space must overwrite the current character on the screen. Each editing mode opens a window at the current line. The window width is the value of the COLUMNS variable if it is defined; oth- erwise the width is 80 character spaces. If the line is longer than the window width minus two, the system notifies you by displaying a mark at the end of the window. As the cursor moves and reaches the window boundaries, the window is centered about the cursor. The marks displayed are: > Indicates that the line extends on the right side of the win- dow. < Indicates that the line extends on the left side of the window. * Indicates that the line extends on both sides of the window. The search commands in each edit mode provide access to the Korn shell history file. Only strings are matched. If the leading character in the string is a \^ (caret), the match must begin at the first character in the line. This section discusses: * emacs Editing Mode * vi Editing Mode * Related Information emacs Editing Mode The emacs mode is entered when you enable either the emacs or gmacs option. The only difference between these two modes is the way each handles the Ctrl-T edit command. To edit, move the cur- sor to the point needing correction and insert or delete charac- ters or words, as needed. All of the editing commands are con- trol characters or escape sequences. Edit commands operate from any place on a line (not just at the beginning). Do not press the Enter key or line-feed (down arrow) key after edit commands, except as noted. Ctrl-F Moves the cursor forward (right) one character. Esc-F Moves the cursor forward one word (a string of characters consisting of only letters, digits, and underscores). Ctrl-B Moves the cursor backward (left) one character. Esc-B Moves the cursor backward one word. Ctrl-A Moves the cursor to the beginning of the line. Ctrl-E Moves the cursor to the end of the line. Ctrl-] c Moves the cursor forward on the current line to the in- dicated character. Esc-Ctrl-] c Moves the cursor backward on the current line to the indicated character. Ctrl-X Ctrl-X Interchanges the cursor and the mark. ERASE Deletes the previous character. (User-defined erase char- acter as defined by the stty command, usually the Ctrl-H key se- quence.) Ctrl-D Deletes the current character. Esc-D Deletes the current word. Esc-Backspace Deletes the previous word. Esc-H Deletes the previous word. Esc-Delete Deletes the previous word. If your interrupt charac- ter is the Delete key, then this command does not work. Ctrl-T Transposes the current character with the next character in emacs mode. Transposes the two previous characters in gmacs mode. Ctrl-C Capitalizes the current character. Esc-C Capitalizes the current word. Esc-L Changes the current word to lowercase. Ctrl-K Deletes from the cursor to the end of the line. If pre- ceded by a numerical parameter whose value is less than the current cursor position, this editing command deletes from the given position up to the cursor. If preceded by a numerical parameter whose value is greater than the current cursor posi- tion, this editing command deletes from the cursor up to the given cursor position. Ctrl-W Deletes from the cursor to the mark. Esc-P Pushes the region from the cursor to the mark on the stack. KILL (User-defined kill character as defined by the stty command, usually the Ctrl-G key sequence or an @ (ampersand). Kills the entire current line. If two kill characters are entered in suc- cession, all subsequent kill characters cause a line feed (useful when using paper terminals). Ctrl-Y Restores the last item removed from the line. (Yanks the item back to the line.) Ctrl-L Line feeds and prints the current line. Ctrl-@ (Null character) Sets a mark. Esc-space Sets a mark. Ctrl-J (New line) Executes the current line. Ctrl-M (Return) Executes the current line. EOF Processes the end-of-file character, normally the Ctrl-D key sequence, as an end-of-file only if the current line is null. Ctrl-P Fetches the previous command. Each time the Ctrl-P key sequence is entered, the previous command back in time is ac- cessed. Moves back one line when not on the first line of a mul- tiple line command. Esc-< Fetches the least recent (oldest) history line. Esc-> Fetches the most recent (youngest) history line. Ctrl-N Fetches the next command line. Each time the Ctrl-N key sequence is entered, the next command line forward in time is ac- cessed. Ctrl-R String Reverses search history for a previous command line containing the string specified by the String parameter. If a value of 0 is given, the search is forward. The specified string is terminated by an Enter or new-line character. If the string is preceded by a \^ (caret character), the matched line must be- gin with the String parameter. If the String parameter is omit- ted, then the next command line containing the most recent String parameter is accessed. In this case, a value of 0 reverses the direction of the search. Ctrl-O (Operate) Executes the current line and fetches the next line relative to the current line from the history file. Esc Digits (Escape) Defines the numeric parameter. The digits are taken as a parameter to the next command. The commands that accept a parameter are Ctrl-F, Ctrl-B, ERASE, Ctrl-C, Ctrl-D, Ctrl-K, Ctrl-R, Ctrl-P, Ctrl-N, Ctrl-], Esc-., Esc-Ctrl-], Esc-_, Esc-B, Esc-C, Esc-D, Esc-F, Esc-H, Esc-L, and Esc-Ctrl-H. Esc Letter (Soft-key) Searches the alias list for an alias named _Letter. If an alias of this name is defined, its value is placed into the input queue. The Letter parameter must not specify one of the escape functions. Esc-[ Letter (Soft-key) Searches the alias list for an alias named __Letter (double underscore). If an alias of this name is defined, its value is placed into the input queue. This command can be used to program function keys on many terminals. Esc-. Inserts on the line the last word of the previous command. If preceded by a numeric parameter, the value of this parameter determines which word to insert rather than the last word. Esc-_ Same as the Esc-. (Escape, dash, period) key sequence. Esc-* Attempts file name substitution on the current word. An asterisk is appended if the word does not match any file or con- tain any special pattern characters. Esc-Esc File name completion. Replaces the current word with the longest common prefix of all file names that match the current word with an asterisk appended. If the match is unique, a / (slash) is appended if the file is a directory and a space is ap- pended if the file is not a directory. Esc-= Lists the files that match the current word pattern as if an asterisk were appended. Ctrl-U Multiplies the parameter of the next command by 4. \ Escapes the next character. Editing characters and the ERASE, KILL and INTERRUPT (normally the Delete key) characters can be entered in a command line or in a search string if preceded by a \ (backslash). The backslash removes the next character's edit- ing features, if any. Ctrl-V Displays the version of the shell. Esc-# Inserts a # (pound sign) at the beginning of the line and then executes the line. This causes a comment to be inserted in the history file. vi Editing Mode The vi editing mode has two typing modes. When you enter a com- mand, you are in Input mode. To edit, you must enter the Control mode by pressing the Escape key. Most control commands accept an optional repeat Count parameter prior to the command. When in vi mode on most systems, canonical processing is initially enabled. The command is echoed again if: * The speed is 1200 baud or greater * The command contains any control characters * Less than one second has elapsed since the prompt was printed. The Esc character terminates canonical processing for the remainder of the command, and you can then modify the command line. This scheme has the advantages of canonical processing with the type-ahead echoing of raw mode. If the viraw option is also set, canonical processing is always disabled. This mode is implicit for systems that do not support two alternate end-of- line delimiters and might be helpful for certain terminals. Available vi edit commands are grouped in the following categories: * Input * Motion * Search * Text Modification * Miscellaneous. Input Edit Commands Note: By default, the editor is in input mode. ERASE (User-defined erase character as defined by the stty com- mand, usually Ctrl-H or #.) Deletes the previous character. Ctrl-W Deletes the previous blank separated word. Ctrl-D Terminates the shell. Ctrl-V Escapes the next character. Editing characters, such as the ERASE or KILL characters, can be entered in a command line or in a search string if preceded by a Ctrl-V key sequence. The Ctrl-V key sequence removes the next character's editing features (if any). \ Escapes the next ERASE or KILL character. Motion Edit Commands Motion edit commands move the cursor: [Count]l Moves the cursor forward (right) one character. [Count]w Moves the cursor forward one alphanumeric word. [Count]W Moves the cursor to the beginning of the next word that follows a blank. [Count]e Moves the cursor to the end of the current word. [Count]E Moves the cursor to the end of the current blank- separated word. [Count]h Moves the cursor backward (left) one character. [Count]b Moves the cursor backward one word. [Count]B Moves the cursor to the previous blank-separated word. [Count]| Moves the cursor to the column specified by the Count parameter. [Count]fc Finds the next character c in the current line. [Count]Fc Finds the previous character c in the current line. [Count]tc Equivalent to f followed by h. [Count]Tc Equivalent to F followed by l. [Count]; Repeats for the number of times specified by the Count parameter the last single-character find command: f, F, t, or T. [Count], Reverses the last single-character find command the number of times specified by the Count parameter. 0 Moves the cursor to the start of a line. \^ Moves the cursor to the first nonblank character in a line. $ Moves the cursor to the end of a line. Search Edit Commands Search edit commands access your command history: [Count]k Fetches the previous command. [Count]- Equivalent to the k command. [Count]j Fetches the next command. Each time the j command is entered, the next command is accessed. [Count]+ Equivalent to the j command. [Count]G Fetches the command whose number is specified by the Count parameter. The default is the least recent history com- mand. /String Searches backward through history for a previous command containing the specified string. The string is terminated by a RETURN or new-line character. If the specified string is preced- ed by a \^ (caret ), the matched line must begin with the String parameter. If the value of the String parameter is null, the previous string is used. ?String Same as /String except that the search is in the forward direction. n Searches for the next match of the last pattern to /String or ? commands. N Searches for the next match of the last pattern to /String or ? commands, but in the opposite direction. Searches history for the string entered by the previous /String command. Text-Modification Edit Commands Text-modification edit commands modify the line: a Enters the input mode and enters text after the current charac- ter. A Appends text to the end of the line. Equivalent to the $a com- mand. [Count]cMotion c[Count]Motion Deletes the current character through the charac- ter to which the Motion parameter specifies to move the cursor, and enters input mode. If the value of the Motion parameter is c, the entire line is deleted and the input mode is entered. C Deletes the current character through the end of the line and enters input mode. Equivalent to the c$ command. S Equivalent to the cc command. D Deletes the current character through the end of line. Equivalent to the d$ command. [Count]dMotion d[Count]Motion Deletes the current character up to and including the character specified by the Motion parameter. If Motion is d, the entire line is deleted. i Enters the input mode and inserts text before the current char- acter. I Inserts text before the beginning of the line. Equivalent to the 0i command. [Count]P Places the previous text modification before the cursor. [Count]p Places the previous text modification after the cursor. R Enters the input mode and types over the characters on the screen. [Count]rc Replaces the number of characters specified by the Count parameter, starting at the current cursor position, with the characters specified by the c parameter. This command also advances the cursor after the characters are replaced. [Count]x Deletes the current character. [Count]X Deletes the preceding character. [Count]. Repeats the previous text-modification command. [Count]\~ Inverts the case of the number of characters specified by the Count parameter, starting at the current cursor position, and advances the cursor. [Count]_ Appends the word specified by the Count parameter of the previous command and enters input mode. The last word is used if the Count parameter is omitted. * Appends an * (asterisk) to the current word and attempts file name substitution. If no match is found, it rings the bell. Otherwise, the word is replaced by the matching pattern and input mode is entered. \ File name completion. Replaces the current word with the longest common prefix of all file names matching the current word with an asterisk appended. If the match is unique, a / (slash) is appended if the file is a directory. A space is appended if the file is not a directory. Miscellaneous Edit Commands Miscellaneous edit commands include: [Count]yMotion y[Count]Motion Yanks the current character up to and including the character marked by the cursor position specified by the Motion parameter and puts all of these characters into the delete buffer. The text and cursor are unchanged. Y Yanks from the current position to the end of the line. Equivalent to the y$ command. u Undoes the last text-modifying command. U Undoes all the text-modifying commands performed on the line. [Count]v Returns the command fc -e ${VISUAL:-${EDITOR:-vi}} Count in the input buffer. If the Count parameter is omitted, then the current line is used. Ctrl-L Line feeds and prints the current line. This command is effective only in control mode. Ctrl-J (New line) Executes the current line, regardless of the mode. Ctrl-M (Return) Executes the current line, regardless of the mode. # Sends the line after inserting a # (pound sign) in front of the line. Useful if you want to insert the current line in the history without executing it. = Lists the file names that match the current word as if an as- terisk were appended to it. @Letter Searches the alias list for an alias named _Letter. If an alias of this name is defined, its value is placed into the input queue for processing.