home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-01 | 51.1 KB | 1,255 lines |
-
-
-
- KSH(1) KSH(1)
-
-
- NNAAMMEE
- ksh - Bourne / Korn Shell (Public Domain)
-
- SSYYNNOOPPSSIISS
- kksshh [--sstt] [--cc _c_o_m_m_a_n_d] [_f_i_l_e [_a_r_g_u_m_e_n_t _._._.]]
-
- IINNTTRROODDUUCCTTIIOONN
- This document only summarizes the System V, release 2
- shell features. All of the System V features except for
- ``restricted mode'' are implemented. See also the BUGS
- section.
-
- Features of the Korn shell are described in more detail.
- Only a subset of the Korn shell features are currently
- implemented.
-
- DDEESSCCRRIIPPTTIIOONN
- CCoommmmaanndd ssyynnttaaxx
- The ``#'' character begins a one-line comment, unless the
- ``#'' occurs inside a word. The tokens ``;'', ``|'',
- ``&'', ``;;'', ``||'', ``&&'', ``('', and ``)'' stand by
- themselves. A _w_o_r_d is a sequence of any other non-
- whitespace characters, which may also contain quoted
- strings (quote character are ``''', ``"'', ```'', or a
- matching ``${ }'' or ``$( )'' pair). A _n_a_m_e is an
- unquoted word made up of letters, digits, or ``_''. Any
- number of whitespace characters (space and tab) may sepa-
- rate words and tokens.
-
- In the following syntax, { ... }? indicates an optional
- thing, { ... }* indicates zero or more repetitions, { ...
- | ... } indicates alternatives.
-
- statement:
- (( list ))
- {{ list ;; }}
- ffoorr name { iinn { word }* }? ddoo list ;; ddoonnee
- { wwhhiillee | uunnttiill } list ;; ddoo list ;; ddoonnee
- iiff list ;; tthheenn list ;; { eelliiff list ;; tthheenn list ;; }*
- { eellssee list ;; }?ffii
- ccaassee name iinn { (( word { || word } )) list ;;;; }* eessaacc
- ffuunnccttiioonn name {{ list ;; }}
- name (()) {{ list ;; }}
- ttiimmee pipe
- The opening parenthesis of the pattern is optional.
- Redirection may occur at the beginning or end of a
- statement.
-
- command:
- { name=word }* { word }*
- Redirection may occur anywhere in a command.
-
- list:
- cond
-
-
-
- April 1992 1
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- cond ;; list
- cond && list
-
- cond:
- pipe
- pipe &&&& cond
- pipe |||| cond
-
- pipe:
- statement { || statement }*
-
- AAlliiaass eexxppaannssiioonn
- Alias expansion occurs when the first word of a statement
- is a defined alias, except when that alias is already
- being expanded. It also occurs after the expansion of an
- alias whose definition ends with a space.
-
- SShheellll vvaarriiaabblleess
- The following standard special variables exist: !!, ##, $$,
- --, ??.
-
- _ In interactive use this parameter is set to the
- last word of the previous command. When a command
- is executed this parameter is set to the full path
- of the command and placed in the environment for
- the command. See also MMAAIILLPPAATTHH.
-
- CDPATH The search path for the _c_d command.
-
- ENV If this variable is set at start-up (after any pro-
- file files are executed), the expanded value is
- used as shell start-up file. It typically contains
- function and alias definitions.
-
- FCEDIT The editor used by the _f_c command. During startup
- the shell checks the value of FFCCEEDDIITT, EEDDIITTOORR and
- finally VVIISSUUAALL to try and determin what command
- line edit mode to use. Note that this is not
- strictly ksh compatible behaviour.
-
- IFS _I_n_t_e_r_n_a_l _f_i_e_l_d _s_e_p_a_r_a_t_o_r, used during substitution
- and the _r_e_a_d command.
-
- HOME The default directory for the _c_d command.
-
- MAIL If set, the user will be informed of the arrival of
- mail in the named file. This variable is ignored
- if the MMAAIILLPPAATTHH variable is set.
-
- MAILCHECK
- How often, in seconds, the shell will check for
- mail in the file(s) specified by MMAAIILL or MMAAIILLPPAATTHH.
- If 0, the shell checks before each prompt. The
- default is 600 seconds.
-
-
-
- April 1992 2
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- MAILPATH
- A list of files to be checked for mail. The list
- is colon separated, and each file may be followed
- by a ?? and a message to be printed if new mail has
- arrived. Command and parameter substitution is
- performed on the message, and the parameter $$__ is
- set to the name of the file. The default message
- is ``you have mail in $_''.
-
- PATH The search path for executable commands and ..'d
- files.
-
- PPID The process number of the parent of the shell.
-
- PS1 PS2
- PPSS11 is the primary prompt for interactive shells.
- Dollar substitution is performed, and !! is replaced
- with the command number (see _f_c).
-
- PWD OLDPWD
- The current and previous working directories.
-
- RANDOM A random integer. The random number generator may
- be seeded by assigning an integer value to this
- variable.
-
- SECONDS
- The number of seconds since the shell timer was
- started or reset. Assigning an integer value to
- this variable resets the timer.
-
- COLUMNS
- The width to use for the commandline editing (emacs
- mode only).
-
- HISTFILE
- The name of the file to read initial history from.
- The default is "$$HHOOMMEE//..ppddkksshh__hhiisstt". When the shell
- exits it will overwrite this file with its current
- history. This behaviour will almost certainly
- cause grief when multiple shells are being run by
- the same user. Making the file read-only will
- allow each shell to start with a set history and
- avoid overwriting the file.
-
- HISTSIZE
- The number of history items to save in HHIISSTTFFIILLEE.
-
- SSuubbssttiittuuttiioonn
- In addition to the System Vr2 substitutions, the following
- are available.
-
- $(command)
- Like `command`, but no escapes are recognized.
-
-
-
- April 1992 3
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- $(<file)
- Equivalent to $(cat file), but without forking.
-
- ${#var}
- The length of the string value of _v_a_r, or the num-
- ber of arguments if _v_a_r is ** or @@.
-
- ${var#pattern} ${var##pattern}
- If _p_a_t_t_e_r_n matches the beginning of the value of
- _v_a_r, the matched text is deleted from the result of
- substitution. A single ## results in the shortest
- match, two ##'s results in the longest match.
-
- ${var%pattern} ${var%%pattern}
- Like ## substition, but deleting from the end of the
- value.
-
- EExxpprreessssiioonnss
- Expressions can be used with the lleett command, as numeric
- arguments to the tteesstt command, and as the value of an
- assignment to an integer variable.
-
- Expression may contain alpha-numeric variable identifiers
- and integer constants and may be combined with the follow-
- ing operators:
-
- == != <= < > >= + - * / % ! ( )
-
- CCoommmmaanndd eexxeeccuuttiioonn
- After evaluation of keyword assignments and arguments, the
- type of command is determined. A command may execute a
- shell function, a shell built-in, or an executable file.
-
- Any keyword assignments are then performed according to
- the type of command. In function calls assignments are
- local to the function. Assignments in built-in commands
- marked with a persist, otherwise they are temporary.
- Assignments in executable commands are exported to the
- sub-process executing the command.
-
- Even on systems where the exec() family does not support
- #! notation for scripts, ksh can be configured to fake
- it.
-
- There are several built-in commands.
-
- : Only expansion and assignment are performed. This
- is the default if a command has no arguments.
-
- . _f_i_l_e Execute the commands in _f_i_l_e without forking. The
- file is searched in the directories of $PATH.
- Passing arguments is not implemented.
-
-
-
-
-
- April 1992 4
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- alias [_n_a_m_e==_v_a_l_u_e _._._._]
- Without arguments, aalliiaass lists all aliases and
- their values. For any name without a value, its
- value is listed. Any name with a value defines an
- alias, see "Alias Expansion" above. Korn's tracked
- aliases are not implemented, but System V command
- hashing is (see "hash").
-
- alias -d [_n_a_m_e==_v_a_l_u_e _._._._]
- Directory aliases for tilde expansion, eg.
- alias -d fac=/usr/local/usr/facilities
- cd ~fac/bin
-
- break [_l_e_v_e_l_s]
-
- builtin _c_o_m_m_a_n_d _a_r_g _._._.
- _C_o_m_m_a_n_d is executed as a built-in command.
-
- cd [_p_a_t_h]
- Set the working directory to _p_a_t_h. If the parame-
- ter CDPATH is set, it lists the search path for the
- directory containing _p_a_t_h. A null path means the
- current directory. If _p_a_t_h is missing, the home
- directory ($HOME) is used. If _p_a_t_h is --, the pre-
- vious working directory is used. If _p_a_t_h is ....,
- the shell changes directory to the parent direc-
- tory, as determined from the value of PWD. The PWD
- and OLDPWD variables are reset.
-
- cd _o_l_d _n_e_w
- The string _n_e_w is substituted for _o_l_d in the cur-
- rent directory, and the shell attempts to change to
- the new directory.
-
- continue [_l_e_v_e_l_s]
-
- echo ...
- _E_c_h_o is replaced with the alias echo='print' in the
- Korn shell.
-
- eval _c_o_m_m_a_n_d _._._.
-
- exec _c_o_m_m_a_n_d _a_r_g _._._.
- The executable command is executed without forking.
- If no arguments are given, any IO redirection is
- permanent.
-
- exit [_s_t_a_t_u_s]
-
- fc [--ee _e_d_i_t_o_r] [--llnnrr] [_f_i_r_s_t [_l_a_s_t]]
- _F_i_r_s_t and _l_a_s_t select commands. Commands can be
- selected by history number, or a string specifing
- the most recent command starting with that string.
- The --ll option lists the command on stdout, and --nn
-
-
-
- April 1992 5
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- inhibits the default command numbers. The --rr
- option reverses the order of the list. Without --ll,
- the selected commands can be edited by the editor
- specified with the --ee option, or if no --ee is speci-
- fied, the $$FFCCEEDDIITT editor, then executed by the
- shell.
-
- fc --ee -- [--gg] [_o_l_d==_n_e_w] [_c_o_m_m_a_n_d]
- Re-execute the selected command (the previous com-
- mand by default) after performing the optional sub-
- stitution of _o_l_d with _n_e_w. If --gg is specified, all
- occurrences of _o_l_d are replaced with _n_e_w. This
- command is usually accessed with the predefined
- alias r=``fc -e -''.
-
- getopts
- See the attached manual page.
-
- hash [--rr] [_n_a_m_e _._._.]
- Without arguments, any hashed executable command
- pathnames are listed. The --rr flag causes all
- hashed commands to be removed. Each _n_a_m_e is
- searched as if it were a command name and added to
- the hash table if it is an executable command.
-
- kill [--_s_i_g_n_a_l] _p_r_o_c_e_s_s ...
- Send a signal (TERM by default) to the named pro-
- cess. The signal may be specified as a number or a
- mnemonic from <signal.h> with the SIG prefix
- removed.
-
- let [_e_x_p_r_e_s_s_i_o_n _._._.]
- Each expression is evaluated, see "Expressions"
- above. A zero status is returned if the last
- expression evaluates to a non-zero value, otherwise
- a non-zero status is returned. Since may expres-
- sions need to be quoted, _(_( _e_x_p_r _)_) is syntactic
- sugar for _l_e_t _"_e_x_p_r_".
-
- print [--nnrreeuu_n] [_a_r_g_u_m_e_n_t _._._.]
- PPrriinntt prints its arguments on the standard output,
- separated by spaces, and terminated with a newline.
- The --nn option eliminates the newline.
-
- By default, certain C escapes are translated.
- These include \b, \f, \n, \r, \t, \v, and \### (#
- is an octal digit). \c is equivalent to the --nn
- option. This expansion may be inhibitted with the
- --rr option, and may be re-enabled with the addition
- of the --ee option.
-
- read [--rruu_n] _n_a_m_e _._._.
- The first variable name may be of the form
- _n_a_m_e??_p_r_o_m_p_t.
-
-
-
- April 1992 6
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- readonly [_n_a_m_e _._._.]
-
- return [_s_t_a_t_u_s]
-
- set [++--_[_a_-_z_]] [++--oo _k_e_y_w_o_r_d] ...
- Set (--) or clear (++) a shell option:
- -a allexport all new variable are
- created with export attribute
- -e errexit exit on non-zero sta-
- tus [incorrect]
- bgnice background jobs are
- run with lower priority
-
- emacs BRL emacs-like line
- editing
- ignoreeof shell will not exit
- of EOF, must use _e_x_i_t
- -k keyword variable assignments
- are recognized anywhere in command
- markdirs [not implemented]
- -m monitor job control enabled
- (default for interactive shell)
- -n noexec compile input but do
- not execute (ignored if interactive)
- -f noglob don't expand file-
- names
- -u nounset dollar expansion of
- unset variables is an error
- -v verbose echo shell commands
- on stdout when compiling
- -h trackall add command pathnames
- to hash table
- vi VI-like line editing
- -x xtrace echo simple commands
- while executing
-
- set [----] _a_r_g _._._.
- Set shell arguments.
-
- shift [_n_u_m_b_e_r]
-
- test See the attached manual page.
-
- times
-
- trap [_h_a_n_d_l_e_r] [_s_i_g_n_a_l _._._.]
-
- typeset [++--iirrttxx] [_n_a_m_e[==_v_a_l_u_e] ...]
- If no arguments are given, lists all variables and
- their attributes.
-
- If options but no names are given, lists variables with
- specified attributes, and their values if unless ``+'' is
- used.
-
-
-
- April 1992 7
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- If names are given, set the attributes of the named vari-
- ables. Variables may also be assigned a value. If used
- inside a function, the created variable are local to the
- function.
-
- The attributes are as follows. -iThe variable's value is
- stored as an integer.
- -xThe variable is exported to the enviroment.
- -rThe variable is read-only cannot be reassigned a value.
- -tTrace (not implemented).
- -fList functions instead of variable.
-
- uulliimmiitt [ --<<OOZZ>> ] [ _n ]
-
- --cc Impose a size limit of _n blocks on the size of
- core dumps.
-
- --dd Impose a size limit of _n blocks on the size of
- the data area.
-
- --ff Impose a size limit of _n blocks on files writ-
- ten by the shell and its child processes
- (files of any size may be read).
-
- --mm Impose a soft limit of _n blocks on the size of
- physical memory.
-
- --tt Impose a time limit of _n seconds to be used by
- each process.
-
- If no option is given, --ff is assumed. If _n is
- omitted, the current limit is printed. As far as
- uulliimmiitt is concerned, a ``block'' is 512 bytes.
-
- You may lower your own resource limit, but only a
- super-user (see _s_u(1M)) can raise a limit.
-
- umask [_v_a_l_u_e]
-
- unalias _n_a_m_e _._._.
- The aliases for the given names are removed.
-
- unset [--ff] _n_a_m_e _._._.
-
- wait [_p_r_o_c_e_s_s_-_i_d]
-
- whence [--vv] name ...
- For each name, the type of command is listed. The
- --vv flag causes function and alias values to be
- listed.
-
- JJoobb CCoonnttrrooll
- Job control features are enabled by the --mm or --oo mmoonniittoorr
- flags. When job control is enabled, and the system
-
-
-
- April 1992 8
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- supports job control, background commands and foreground
- commands that have been stopped (usually by a SIGTSTP sig-
- nal generated by typing _^_Z) are placed into separate indi-
- vidual _p_r_o_c_e_s_s _g_r_o_u_p_s. The following commands are used to
- manipulate these process groups:
-
- jjoobbss Display information about the controlled
- jobs. The job number is given preceeded by
- a percent sign, followed by a plus sign if
- it is the ``current job'', or by a minus
- sign if it is the ``previous job'', then
- the process group number for the job, then
- the command.
- kkiillll [--_s_i_g_n_a_l] _j_o_b ...
- Send a signal (TERM by default) to the
- named job process group.
- ffgg [ _j_o_b ] Resume the stopped foreground job in the
- foreground. If the process group _n is not
- specified then the ``current job'' is
- resumed.
- bbgg [ _j_o_b ] Resume the stopped foreground job in the
- background. If the process group _n is not
- specified then the ``current job'' is
- resumed.
-
- The ffgg, bbgg, kkiillll, and wwaaiitt commands may refer to jobs with
- the following ``percent'' sequences. The percent sign is
- optional with the fg and bg commands.
-
- %%++(%%--) If there is a ``current job'' (``previous
- job''), then that job is selected.
- %%_n If the specified job number is one of the known
- jobs, then that job is selected.
- %%_s_t_r_i_n_g If the string matches the initial part of a
- job's command, then that job is selected.
- %%??_s_t_r_i_n_g As above, but the string may match any portion
- of the command.
-
- If the system does not support job control, monitor mode
- enables job reporting. The jobs and kill commands func-
- tions as above, and you will be informed when background
- jobs complete. Fg and bg are not availiable.
-
- IInntteerraaccttiivvee IInnppuutt LLiinnee EEddiittiinngg
- When the eemmaaccss option is set, interactive input line edit-
- ing is enabled. This mode is slightly different from the
- emacs mode in AT&T's KornShell. In this mode various
- _e_d_i_t_i_n_g _c_o_m_m_a_n_d_s (typically bound to one or more control
- characters) cause immediate actions without waiting for a
- new-line. Several _e_d_i_t_i_n_g _c_o_m_m_a_n_d_s are bound to particu-
- lar control characters when the shell is invoked; these
- bindings can be changed using the following commands:
-
- bbiinndd The current bindings are listed.
-
-
-
- April 1992 9
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- bbiinndd [ _s_t_r_i_n_g ] = [ _e_d_i_t_i_n_g_-_c_o_m_m_a_n_d ]
- The specified _e_d_i_t_i_n_g _c_o_m_m_a_n_d is bound
- to the given _s_t_r_i_n_g, which should con-
- sist of a control character (which may
- be written using ``caret notation''
- ^^_x), optionally preceded by one of the
- two prefix characters. Future input
- of the _s_t_r_i_n_g will cause the _e_d_i_t_i_n_g
- _c_o_m_m_a_n_d to be immediately invoked.
- Note that although only two prefix
- characters (normal ESC and ^X) are
- supported, some multi-character
- sequences can be supported:
- bind '^[['=prefix-2
- bind '^XA'=up-history
- bind '^XB'=down-history
- bind '^XC'=forward-char
- bind '^XC'=backward-char
- will bind the arrow keys on an ANSI
- terminal. Of course some escape
- sequences won't work out quite that
- nicely.
- bbiinndd --mm [ _s_t_r_i_n_g ] = [ _s_u_b_s_t_i_t_u_t_e ]
- The specified input _s_t_r_i_n_g will after-
- wards be immediately replaced by the
- given _s_u_b_s_t_i_t_u_t_e string, which may
- contain _e_d_i_t_i_n_g _c_o_m_m_a_n_d_s.
-
- The following _e_d_i_t_i_n_g _c_o_m_m_a_n_d_s are available; first the
- command name is given followed by its default binding (if
- any) using caret notation (note that the ASCII ESC charac-
- ter is written as ^[), then the editing function performed
- is decribed. Note that _e_d_i_t_i_n_g _c_o_m_m_a_n_d names are used
- only with the bbiinndd command. Furthermore, many _e_d_i_t_i_n_g
- _c_o_m_m_a_n_d_s are useful only on terminals with a visible cur-
- sor. The default bindings were chosen to resemble corre-
- sponding EMACS key bindings. The users tty characters
- (eg. erase) are bound to reasonable substitutes.
-
- aabboorrtt ^^GG Useful as a response to a
- request for a sseeaarrcchh--
- hhiissttoorryy pattern in order
- to abort the search.
- aauuttoo--iinnsseerrtt Simply causes the charac-
- ter to appear as literal
- input. (Most ordinary
- characters are bound to
- this.)
- bbaacckkwwaarrdd--cchhaarr ^^BB Moves the cursor backward
- one character.
- bbaacckkwwaarrdd--wwoorrdd ^^[[bb Moves the cursor backward
- to the beginning of a
- word.
- bbeeggiinnnniinngg--ooff--lliinnee ^^AA Moves the cursor to the
-
-
-
- April 1992 10
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- beginning of the input
- line (after the prompt
- string).
- ccoommpplleettee ^^[[^^[[ Automatically completes as
- much as is unique of the
- hashed command name or the
- file name containing the
- cursor. If the entire
- remaining command or file
- name is unique a space is
- printed after its comple-
- tion, unless it is a
- directory name in which
- case // is postpended. If
- there is no hashed command
- or file name with the cur-
- rent partial word as its
- prefix, a bell character
- is output (usually causing
- a ``beep'').
- ccoommpplleettee--ccoommmmaanndd ^^XX^^[[ Automatically completes as
- much as is unique of the
- hashed command name having
- the partial word up to the
- cursor as its prefix, as
- in the ccoommpplleettee command
- described above. Only
- command and function names
- seen since the last hhaasshh
- --rr command are available
- for completion; the hhaasshh
- command may be used to
- register additional names.
- ccoommpplleettee--ffiillee ^^[[^^XX Automatically completes as
- much as is unique of the
- file name having the par-
- tial word up to the cursor
- as its prefix, as in the
- ccoommpplleettee command described
- above.
- ccooppyy--llaasstt--aarrgg ^^[[__ The last word of the pre-
- vious command is inserted
- at the cursor. Note I/O
- redirections do not count
- as words of the command.
- ddeelleettee--cchhaarr--bbaacckkwwaarrdd EERRAASSEE Deletes the character
- before the cursor.
- ddeelleettee--cchhaarr--ffoorrwwaarrdd Deletes the character
- after the cursor.
- ddeelleettee--wwoorrdd--bbaacckkwwaarrdd ^^[[EERRAASSEE Deletes characters before
- the cursor back to the
- beginning of a word.
- ddeelleettee--wwoorrdd--ffoorrwwaarrdd ^^[[dd Deletes characters after
- the cursor up to the end
-
-
-
- April 1992 11
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- of a word.
- ddoowwnn--hhiissttoorryy ^^NN Scrolls the history buffer
- forward one line (later).
- Each input line originally
- starts just after the last
- entry in the history
- buffer, so ddoowwnn--hhiissttoorryy is
- not useful until either
- sseeaarrcchh--hhiissttoorryy or uupp--
- hhiissttoorryy has been per-
- formed.
- eenndd--ooff--lliinnee ^^EE Moves the cursor to the
- end of the input line.
- eeoott ^^__ Acts as an end-of-file;
- this is useful because
- edit-mode input disables
- normal terminal input
- canonicalization.
- eeoott--oorr--ddeelleettee ^^DD Acts as eot if alone on a
- line; otherwise acts as
- delete-char-forward.
- eexxcchhaannggee--ppooiinntt--aanndd--mmaarrkk ^^XX^^XX Places the cursor where
- the mark is, and sets the
- mark to where the cursor
- was.
- ffoorrwwaarrdd--cchhaarr ^^FF Moves the cursor forward
- one position.
- ffoorrwwaarrdd--wwoorrdd ^^[[ff Moves the cursor forward
- to the end of a word.
- kkiillll--lliinnee KKIILLLL Deletes the entire input
- line.
- kkiillll--ttoo--eeooll ^^KK Deletes the input from the
- cursor to the end of the
- line.
- kkiillll--rreeggiioonn ^^WW Deletes the input between
- the cursor and the mark.
- lliisstt ^^[[?? Prints a sorted, colum-
- nated list of hashed com-
- mand names or file names
- (if any) that can complete
- the partial word contain-
- ing the cursor. Directory
- names have // postpended to
- them, and executable file
- names are followed by **.
- lliisstt--ccoommmmaanndd ^^XX?? Prints a sorted, colum-
- nated list of hashed com-
- mand names (if any) that
- can complete the partial
- word containing the cur-
- sor.
- lliisstt--ffiillee Prints a sorted, colum-
- nated list of file names
- (if any) that can complete
-
-
-
- April 1992 12
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- the partial word contain-
- ing the cursor. File type
- indicators are postpended
- as described under lliisstt
- above.
- nneewwlliinnee ^^JJ _a_n_d ^^MM Causes the current input
- line to be processed by
- the shell. (The current
- cursor position may be
- anywhere on the line.)
- nneewwlliinnee--aanndd--nneexxtt ^^OO Causes the current input
- line to be processed by
- the shell, and the next
- line from history becomes
- the current line. This is
- only useful after an up-
- history or search-history.
- nnoo--oopp QQUUIITT Does nothing.
- pprreeffiixx--11 ^^[[ Introduces a 2-character
- command sequence.
- pprreeffiixx--22 ^^XX Introduces a 2-character
- command sequence.
- qquuoottee ^^^^ The following character is
- taken literally rather
- than as an _e_d_i_t_i_n_g _c_o_m_-
- _m_a_n_d.
- rreeddrraaww ^^LL Reprints the prompt string
- and the current input
- line.
- sseeaarrcchh--cchhaarraacctteerr ^^]] Search forward in the cur-
- rent line for the next
- keyboard character.
- sseeaarrcchh--hhiissttoorryy ^^RR Enter incremental search
- mode. The internal his-
- tory list is searched
- backwards for commands
- matching the input. An
- initial ``^'' in the
- search string anchors the
- search. The escape key
- will leave search mode.
- Other commands will be
- executed after leaving
- search mode (unless of
- course they are prefixed
- by escape, in which case
- they will almost certainly
- do the wrong thing). Suc-
- cessive sseeaarrcchh--hhiissttoorryy
- commands continue search-
- ing backward to the next
- previous occurrence of the
- pattern. The history
- buffer retains only a
-
-
-
- April 1992 13
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- finite number of lines;
- the oldest are discarded
- as necessary.
- sseett--mmaarrkk--ccoommmmaanndd ^^]]<<ssppaaccee>> Search forward in the cur-
- rent line for the next
- keyboard character.
- ssttuuffff On systems supporting it,
- pushes the bound character
- back onto the terminal
- input where it may receive
- special processing by the
- terminal handler.
- ssttuuffff--rreesseett Acts like ssttuuffff, then
- aborts input the same as
- an interrupt.
- ttrraannssppoossee--cchhaarrss ^^TT Exchanges the two charac-
- ters on either side of the
- cursor, or the two previ-
- ous characters if the cur-
- sor is at end of line.
- uupp--hhiissttoorryy ^^PP Scrolls the history buffer
- backward one line (ear-
- lier).
- yyaannkk ^^YY Inserts the most recently
- killed text string at the
- current cursor position.
- yyaannkk--ppoopp ^^[[yy Immediately after a yyaannkk,
- replaces the inserted text
- string with the next pre-
- vious killed text string.
-
- FFIILLEESS
- ~/.profile
- /etc/profile
-
- SSEEEE AALLSSOO
- Sh(1) on System V or Sun OS.
-
- _U_N_I_X _S_h_e_l_l _P_r_o_g_r_a_m_m_i_n_g_, Stephan G. Kochan, Patrick H.
- Wood, Hayden.
-
- _K_o_r_n_S_h_e_l_l_: _C_o_m_m_a_n_d _a_n_d _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e _(_n_o_t _y_e_t _p_u_b_-
- _l_i_s_h_e_d_)_, Morris Bolsky and David Korn.
-
- AAUUTTHHOORRSS
- Based on the public domain 7th edition Bourne shell.
-
- System V and Korn modifications by Eric Gisin, with con-
- tributions by Ron Natalie, Arnold Robbins, Doug Gwyn, Erik
- Baalbergen, AT&T (getopt(3)), John McMillan and Simon Ger-
- raty.
-
-
-
-
-
-
- April 1992 14
-
-
-
-
-
- KSH(1) KSH(1)
-
-
- DDIIFFFFEERREENNCCEESS FFRROOMM AATT&&TT VVEERRSSIIOONN
- The sseelleecctt statement is not implemented. Variable arrays
- are not implemented. Variable attributes other than inte-
- ger are not implemented. The EERRRR and EEXXIITT traps are not
- implemented for functions. Alias expansion is inhibited
- at the beginning of an alias definition in the AT&T ver-
- sion. Korn evaluates expressions differently [elaborate].
-
- BBUUGGSS
- Interactive shells may occasionally hang while waiting for
- a job in the BSD version.
-
- The 8th bit is stripped in emacs mode.
-
- Quoting double-quote (") characters inside back-quote (`)
- inside double-quotes does not behave properly. Why are
- you doing this?
-
- The emacs mode can ``lose'' stty command done by the user.
-
- Unsetting special variables may cause unexpected results.
-
- Functions declared as having local scope really have
- global scope.
-
- Here documents inside functions do not work correctly.
-
- Exit on error (sseett --ee or sseett --oo eerrrreexxiitt) does not work
- correctly.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- April 1992 15
-
-
-
-
-
- TEST(1) TEST(1)
-
-
- NNAAMMEE
- test - test condition (Korn and 8th edition)
-
- SSYYNNOOPPSSIISS
- tteesstt _e_x_p_r_e_s_s_i_o_n
- [[ _e_x_p_r_e_s_s_i_o_n ]]
-
- DDEESSCCRRIIPPTTIIOONN
- TTeesstteevvaalluuttaatteess tthhee _e_x_p_r_e_s_s_i_o_n aanndd rreettuurrnnss zzeerroo ssttaattuuss iiff
- ttrruuee,, aanndd nnoonn--zzeerroo ssttaattuuss ootthheerrwwiissee.. IItt iiss nnoorrmmaallllyy uusseedd
- aass tthhee ccoonnttrroolllliinngg ccoommmmaanndd ooff tthhee iiff aanndd wwhhiillee ssttaatteemmeennttss..
-
- The following basic expressions are available.
-
- -r file file exists and is
- readable
- -w file file exists and is
- writable
- -x file file exists and is
- executable
- -f file file is a regular
- file
- -d file file is a directory
- -c file file is a character
- special device
- -b file file is a block spe-
- cial device
- -p file file is a named pipe
- -u file file mode has setuid
- bit
- -g file file mode has setgid
- bit
- -k file file mode has sticky
- bit
- -s file file is not empty
- -L file file is a symbolic
- link
- -S file file is a socket
- file -nt file first file is newer
- than second file
- file -ot file first file is older
- than second file
- file -ef file first file is the
- same file as second file
- -t filedes file descriptor is a
- tty device
-
- string string is not null
- -z string string is null
- -n string string is not null
- string = string strings are equal
- string != string strings are not equal
-
- number -eq number numbers compare equal
-
-
-
- Korn shell January 1988 1
-
-
-
-
-
- TEST(1) TEST(1)
-
-
- number -ne number numbers compare not
- equal
- number -ge number numbers compare
- greater than or equal
- number -gt number numbers compare
- greater than
- number -le number numbers compare less
- than or equal
- number -lt number numbers compare less
- than
-
- The above basic expressions may be combined with the fol-
- lowing operators.
-
- expr -o expr logical or
- expr -a expr logical and
- ! expr logical not
- ( expr ) grouping
-
- AAUUTTHHOORR
- Erik Baalbergen. Modified by Arnold Robbins.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Korn shell January 1988 2
-
-
-
-
-
- GETOPTS(1) GETOPTS(1)
-
-
- NNAAMMEE
- getopts - parse command options
-
- SSYYNNOOPPSSIISS
- ggeettooppttss optstring name [arg ...]
-
- DDEESSCCRRIIPPTTIIOONN
- _g_e_t_o_p_t_s is used by shell procedures to parse positional
- parameters and to check for legal options. It supports
- all applicable rules of the command syntax standard (see
- Rules 3-10, _i_n_t_r_o(1)). It should be used in place of the
- _g_e_t_o_p_t(1) command. (See the WWAARRNNIINNGG, below.)
-
- _o_p_t_s_t_r_i_n_g must contain the option letters the command
- using _g_e_t_o_p_t_s will recognize; if a letter is followed by a
- colon, the option is expected to have an argument which
- should be separated from it by white space.
-
- Each time it is invoked, _g_e_t_o_p_t_s will place the next
- option in the shell variable _n_a_m_e and the index of the
- next argument to be processed in the shell variable
- OOPPTTIINNDD. Whenever the shell or a shell procedure is
- invoked, OOPPTTIINNDD is initialized to 11.
-
- When an option requires an option-argument, _g_e_t_o_p_t_s places
- it in the shell variable OOPPTTAARRGG.
-
- If an illegal option is encountered, ?? will be placed in
- _n_a_m_e.
-
- When the end of the options is encountered, _g_e_t_o_p_t_s exits
- with a non-zero exit status. The special option ``----''
- may be used to delimit the end of the options.
-
- By default, _g_e_t_o_p_t_s parses the positional parameters. If
- extra arguments (_a_r_g ...) are given on the _g_e_t_o_p_t_s command
- line, _g_e_t_o_p_t_s will parse them instead.
-
- So all new commands will adhere to the command syntax
- standard described in _i_n_t_r_o(1), they should use _g_e_t_o_p_t_s(1)
- or _g_e_t_o_p_t(3C) to parse positional parameters and check for
- options that are legal for that command (see WWAARRNNIINNGGSS,
- below).
-
- EEXXAAMMPPLLEE
- The following fragment of a shell program shows how one
- might process the arguments for a command that can take
- the options aa or bb, as well as the option oo, which
- requires an option-argument:
-
- wwhhiillee ggeettooppttss aabboo:: cc
- ddoo
- ccaassee $$cc iinn
- aa||bb)) FFLLAAGGSS==$$FFLLAAGGSS$$cc;;;;
-
-
-
- Korn shell January 1988 1
-
-
-
-
-
- GETOPTS(1) GETOPTS(1)
-
-
- oo)) OOAARRGG==$$OOPPTTAARRGG;;;;
- \\??)) eecchhoo $$UUSSAAGGEE 11>>&&22
- eexxiitt 22;;;;
- eessaacc
- ddoonnee
- sshhiifftt OOPPTTIINNDD--11
-
- This code will accept any of the following as equivalent:
-
- ccmmdd --aa --bb --oo ""xxxxxx zz yyyy"" ffiillee
- ccmmdd --aa --bb --oo ""xxxxxx zz yyyy"" ---- ffiillee
- ccmmdd --aabb --oo ""xxxxxx zz yyyy"" ffiillee
- ccmmdd --aabb --oo ""xxxxxx zz yyyy"" ---- ffiillee
-
- SSEEEE AALLSSOO
- intro(1), sh(1).
- getopt(3C) in the _P_r_o_g_r_a_m_m_e_r_'_s _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l.
- _U_N_I_X _S_y_s_t_e_m _V _R_e_l_e_a_s_e _3_._0 _R_e_l_e_a_s_e _N_o_t_e_s.
-
- WWAARRNNIINNGG
- Although the following command syntax rule (see _i_n_t_r_o(1))
- relaxations are permitted under the current implementa-
- tion, they should not be used because they may not be sup-
- ported in future releases of the system. As in the EEXXAAMM--
- PPLLEE section above, aa and bb are options, and the option oo
- requires an option-argument:
-
- ccmmdd --aabbooxxxxxx ffiillee (Rule 5 violation: options with
- option-arguments must not be grouped with other options)
- ccmmdd --aabb --ooxxxxxx ffiillee (Rule 6 violation: there must be
- white space after an option that takes an option-argument)
-
- Changing the value of the shell variable OOPPTTIINNDD or parsing
- different sets of arguments may lead to unexpected
- results.
-
- DDIIAAGGNNOOSSTTIICCSS
- _g_e_t_o_p_t_s prints an error message on the standard error out-
- put when it encounters an option letter not included in
- _o_p_t_s_t_r_i_n_g.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Korn shell January 1988 2
-
-
-