File:  [MW Coherent from dump] / coherent / a / usr / man / COHERENT / ksh
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



ksh                          Command                          ksh




The Korn shell

kksshh _t_o_k_e_n ...

The  COHERENT system  offers  two command  interpreters: sshh,  the
Bourne  shell;  and  kksshh, the  Korn  shell.   sshh  is the  default
COHERENT  command interpreter.   The shell  tutorial  included in
this manual describes the Bourne shell in detail.

This article describes kksshh, the Korn shell.  kksshh is a superset of
the Bourne  shell, and contains  many features that  you may well
find useful.   These include MicroEMACS-style  editing of command
lines; command  hashing; a full-featured aliasing  feature; and a
job-control facility.

***** Invoking ksh *****

To invoke  kksshh from within  the Bourne shell, simply  type kksshh at
the  command-line prompt.   To  use kksshh  as  your default  shell,
instead of sshh, append the command /uussrr/bbiinn/kksshh to the end of your
entry in the file  /eettcc/ppaasssswwdd. (See the Lexicon entry for ppaasssswwdd
for more information on this file.)

You can  invoke kksshh with one or more  built-in options; these are
described below.

***** Commands *****

A _c_o_m_m_a_n_d consists of one or  more _t_o_k_e_n_s. A _t_o_k_e_n is a string of
text  characters  (i.e.,   one  or  more  alphabetic  characters,
punctuation marks,  and numerals) delineated by  spaces, tabs, or
newlines.

A _s_i_m_p_l_e _c_o_m_m_a_n_d consists of the command's name, followed by zero
or more tokens that  represent arguments to the command, names of
files,  or shell  operators.  A  _c_o_m_p_l_e_x  _c_o_m_m_a_n_d will  use shell
constructs  to execute  one or  more commands  conditionally.  In
effect, a  complex command is  a mini-program that  is written in
the shell's programming language and interpreted by kksshh.

***** Shell Operators *****

The  shell  includes  a  number  of  operators that  form  pipes,
redirect  input  and  output  to  commands,  and let  you  define
conditions under which commands are executed.

_c_o_m_m_a_n_d | _c_o_m_m_a_n_d
     The _p_i_p_e  operator: let the  output of one  command serve as
     the input to a second.  You can combine commands with `|' to
     form _p_i_p_e_l_i_n_e_s. A pipeline passes the standard output of the
     first (leftmost) command to the standard input of the second
     command.  For example, in the pipeline

             sort customers | uniq | more


COHERENT Lexicon                                           Page 1




ksh                          Command                          ksh




     kksshh invokes ssoorrtt to sort the contents of file ccuussttoommeerrss.  It
     pipes the output of  ssoorrtt to the command uunniiqq, which outputs
     one unique copy of the text that is input into it.  kksshh then
     pipes the output of uunniiqq to the command mmoorree, which displays
     it  on your  terminal one  screenful at  a time.   Note that
     under   COHERENT,   unlike   MS-DOS,  pipes   are   executed
     concurrently: that is, ssoorrtt does not have to finish its work
     before uunniiqq  and mmoorree can begin to receive  input and get to
     work.

_c_o_m_m_a_n_d ; _c_o_m_m_a_n_d
     Execute  commands  on  a  command  line  sequentially.   The
     command to the left  of the `;' executes to completion; then
     the command  to the right  of it executes.   For example, in
     the command line

             a | b ; c | d

     first  execute  the  pipeline aa  |  bb  then,  when  aa and  bb
     complete, execute the pipeline cc | dd.

_c_o_m_m_a_n_d &
     Execute  a command  in the  background.  This  operator must
     follow the  command, not precede it.   It prints the process
     identifier of the command on the standard output, so you can
     use the  kkiillll command to kill  that process should something
     go  wrong.  This  operator lets  you  execute more  than one
     command simultaneously.  For example, the command

             /etc/fdformat -v /dev/fha0 &

     formats  a high-density,  5.25-inch floppy  disk in  drive 0
     (that is,  drive A); but while the  disk is being formatted,
     kksshh returns  the command line prompt  so you can immediately
     enter another command and begin to work.  If you did not use
     the  `&'  in this  command,  you would  have  to wait  until
     formatting  was  finished  before  you could  enter  another
     command.

     kksshh also  prints a message  on your terminal  when a command
     that you are  running in the background finishes processing.
     It  does not  check  these ``child''  processes very  often,
     however, so a command may have finished some time before kksshh
     informs you  of the fact.   See the Lexicon  article for the
     command ppss  for information on  all processes; also  see the
     description of the built-in command jjoobbss, below.

_c_o_m_m_a_n_d && _c_o_m_m_a_n_d
     Execute a  command upon  success.  kksshh executes  the command
     that  follows  the  token  `&&'  only  if the  command  that
     precedes  it returns  a  zero exit  status, which  signifies
     success.  For example, the command

             cd /etc


COHERENT Lexicon                                           Page 2




ksh                          Command                          ksh



             fdformat -v /dev/fha0 && badscan -o proto /dev/fha0 2400

     formats a  floppy disk, as  described above.  If  the format
     was successful, it  then invokes the command bbaaddssccaann to scan
     the disk for bad  blocks; if it was not successful, however,
     it does nothing.

_c_o_m_m_a_n_d || _c_o_m_m_a_n_d
     Execute  a  command  upon  failure.   This is  identical  to
     operator `&&', except that the second command is executed if
     the  first  returns   a  non-zero  status,  which  signifies
     failure.  For example, the command

             /etc/fdformat -v /dev/fha0 || echo "Format failed!"

     formats a floppy  disk.  If formatting failed, it echoes the
     message  FFoorrmmaatt  ffaaiilleedd!   on  your  terminal;  however,  if
     formatting succeeds, it does nothing.

     Note that the tokens  newline, `;' and `&' bind less tightly
     than `&&'  and `||'.  kksshh parses command  lines from left to
     right if separators bind equally.

>_f_i_l_e
     Redirect  standard  output.   The _s_t_a_n_d_a_r_d  _i_n_p_u_t,  _s_t_a_n_d_a_r_d
     _o_u_t_p_u_t, and _s_t_a_n_d_a_r_d _e_r_r_o_r streams are normally connected to
     the terminal.  A pipeline attaches the output of one command
     to the input  of another command.  In addition, kksshh includes
     a set of operators that redirect input and output into files
     rather than other commands.

     The operator `>' redirects output into a file.  For example,
     the command

             sort customers >customers.sort

     sorts file ccuussttoommeerrss  and writes the sorted output into file
     ccuussttoommeerrss.ssoorrtt.  It creates  ccuussttoommeerrss.ssoorrtt if  it  does not
     exist, and destroys its previous contents if it does exist.

>>_f_i_l_e
     Redirect output  into a file, and append.   If the file does
     not exist,  this operator creates  it; however, if  the file
     already  exists, this  operator appends  the output  to that
     file's contents rather  than destroying those contents.  For
     example, the command

             sort customers.now | uniq >>customers.all

     sorts file ccuussttoommeerrss.nnooww,  pipes its output to command uunniiqq,
     which throws away  duplicate lines of input, and appends the
     results to file ccuussttoommeerrss.aallll.

<_f_i_l_e
     Redirect input.  Here, kksshh  reads the contents of a file and


COHERENT Lexicon                                           Page 3




ksh                          Command                          ksh



     processes them as if  you had typed them from your keyboard.
     For example, the command

             ed textfile <edit.script

     invokes  the  line-editor  eedd  to  edit  tteexxttffiillee;  however,
     instead of reading  editing commands from your keyboard, the
     shell passes  eedd the contents of  eeddiitt.ssccrriipptt.  This command
     would  let you  prepare  an editing  script  that you  could
     execute repeatedly upon files rather than having to type the
     same commands over and over.

<< _t_o_k_e_n
     Prepare  a ``here  document''.  This  operator tells  kksshh to
     accept standard input from  the shell input until it reads a
     line that contains only _t_o_k_e_n. For example, the command

             cat >FOO <<\!
                     Here is some text.
             !

     redirects  all  text  between  `<<\!'  and  `!' to  the  ccaatt
     command.  The  `>' in turn redirects the  output of ccaatt into
     file FFOOOO.   kksshh performs parameter substitution  on the here
     document  unless  the  leading  _t_o_k_e_n is  quoted;  parameter
     substitution and quoting are described below.

_c_o_m_m_a_n_d 22> _f_i_l_e
     Redirect  the  standard  error  stream  into  a  file.   For
     example, the command

             nroff -ms textfile >textfile.p 2>textfile.err

     invokes  the  command   nnrrooffff  to  format  the  contents  of
     tteexxttffiillee.   It  redirects the  output  of  nnrrooffff (i.e.,  the
     standard  output)  into tteexxttffiillee.pp;  it  also redirects  any
     error   messages   that  nnrrooffff   may   generate  into   file
     tteexxttffiillee.eerrrr.

     Note in passing that a command may use up to 20 streams.  By
     default, stream  0 is  the standard  input; stream 1  is the
     standard output;  and stream 2  is the standard  error.  kksshh
     lets  you redirect  any of  these streams  individually into
     files, or combine streams into each other.

<&_n  kksshh can redirect  the standard input and output to duplicate
     other  file  descriptors.   (See  the Lexicon  article  ffiillee
     ddeessccrriippttoorr  for details  on what  these are.)  This operator
     duplicates the standard input from file descriptor _n.

>&_n  Duplicate the  standard output from file  descriptor _n.  For
     example,

             2>&1



COHERENT Lexicon                                           Page 4




ksh                          Command                          ksh



     redirects  file descriptor  2 (the  standard error)  to file
     descriptor 1 (the standard output).

Note that each  command executed as a foreground process inherits
the file  descriptors and signal  traps (described below)  of the
invoking   shell,   modified   by  any   specified   redirection.
Background processes  take input  from the null  device /ddeevv/nnuullll
(unless redirected), and ignore interrupt and quit signals.

***** File-Name Patterns *****

The  shell interprets  an  input token  that contain  any of  the
special characters `?', `*', or `[' as a file name _p_a_t_t_e_r_n.

?  Match any  single character except newline.   For example, the
   command

           ls name?

   will print  the name of  any file that consists  of the string
   nnaammee  plus  any one  character.   If nnaammee  is  followed by  no
   characters, or is followed  by two or more characters, it will
   not be printed.

*  Match  a  string  of  non-newline  characters  of  any  length
   (including zero).

           ls name*

   will print  the name of  any file that begins  with the string
   nnaammee,  regardless  of  whether it  is  followed  by any  other
   characters.  Likewise, the command

           ls name?*

   will print  the name of  any file that consists  of the string
   nnaammee followed  by at least  one character.  Unlike  nnaammee*, the
   token  nnaammee?*  insists  that  be  followed  by  at  least  one
   character before it will be printed.

~_n_a_m_e
   Replace the  name of user _n_a_m_e with  his $HHOOMMEE directory.  For
   example, the command

           ls -l ~norm/src

   lists the  contents of the _s_r_c  subdirectory located under the
   $HHOOMMEE directory for user  nnoorrmm. This spares you from having to
   know where a given user's HOME directory is located.

[_C-_c]
   Enclose alternatives to match a single character.  A hyphen `-
   ' indicates a range of characters.  For example, the command

           ls name[ABC]


COHERENT Lexicon                                           Page 5




ksh                          Command                          ksh




   will  print  the  names  of  files  nnaammeeAA,  nnaammeeBB,  and  nnaammeeCC
   (assuming, of  course, that those  files exist in  the current
   directory).  The command

           ls name[A-K]

   prints the names of files nnaammeeAA through nnaammeeKK (again, assuming
   that they exist in the current directory).

When kksshh reads a token that contains one of the above characters,
it replaces  the token in  the command line  with an alphabetized
list  of file  names  that match  the  pattern.  If  it finds  no
matches,  it passes  the  token unchanged  to  the command.   For
example, when you enter the command


        ls name[ABC]


kksshh  replaces the  token nnaammee[AABBCC] with  nnaammeeAA, nnaammeeBB,  and nnaammeeCC
(again, if  they exist in the current  directory), so the command
now reads:


        ls nameA nameB nameC


It then  passes this second,  transformed version of  the command
line to the command llss.

Note that  the slash `/'  and leading period `.'  must be matched
explicitly  in a  pattern.  The slash,  of course,  separates the
elements of  a path name; while  a period at the  begin of a file
name  usually  (but  not always)  indicates  that  that file  has
special significance.

***** Quoting Text *****

From  time to  time, you  will want to  ``turn off''  the special
meaning of characters.  For example, you may wish to pass a token
that contains a literal asterisk to a command; to do so, you need
a way  to tell kksshh  not to expand  the token into a  list of file
names.  Therefore, kksshh includes the qquuoottaattiioonn ooppeerraattoorrss `\', `"',
and `'';  these ``turn  off'' (or  _q_u_o_t_e) the special  meaning of
operators.

The backslash  `\' quotes the following  character.  For example,
the command








COHERENT Lexicon                                           Page 6




ksh                          Command                          ksh



        ls name\*


lists a file named nnaammee*, and no other.

The shell ignores  a backslash immediately followed by a newline,
called a _c_o_n_c_e_a_l_e_d _n_e_w_l_i_n_e.  This lets you give more arguments to
a command than will fit on one line.  For example, the command


        cc -o output file1.c file2.c file3.c \
                file4.c file5.c file19.c


invokes the C compiler cccc to compile a set of C source files, the
names of which extend over more than one line of input.  You will
find  this to  be extremely  helpful,  especially when  you write
scripts  and  mmaakkeeffiillees,  to help  you  write  neat, easily  read
commands.

A pair of apostrophes ' ' prevents interpretation of any enclosed
special characters.  For example, the command


        find . -name '*.c' -print


finds and  prints the  name of any  C-source file in  the current
directory and any  subdirectory.  The command ffiinndd interprets the
`*'  internally;  therefore, you  want  to  suppress the  shell's
expansion of  that operator,  which is accomplished  by enclosing
that token between apostrophes.

A pair of quotation marks " "  has   the  same   effect.   Unlike
apostrophes, however, kksshh will perform parameter substitution and
command-output  substitution (described  below) within  quotation
marks.  Note  that everything between  quotation marks will  be a
single  argument, even  if there are  spaces between  the tokens.
For example, the command


        grep "x y" *.c


calls  the string-search  command  ggrreepp to  look  for the  string
xx<ssppaaccee>yy.

***** Scripts *****

Shell commands can be stored in a file, or _s_c_r_i_p_t. The command







COHERENT Lexicon                                           Page 7




ksh                          Command                          ksh



        ksh _s_c_r_i_p_t [ _p_a_r_a_m_e_t_e_r ... ]


executes the  commands in  _s_c_r_i_p_t with  a new subshell  kksshh. Each
_p_a_r_a_m_e_t_e_r  is a  value for a  positional parameter,  as described
below.   If  you  have used  the  command  cchhmmoodd  to make  _s_c_r_i_p_t
executable, you may omit the kksshh command.

Parameters  of  the form  `$_n'  represent command-line  arguments
within a  script.  _n can range from zero  through nine; $00 always
gives the  name of the script.  These  parameters are also called
_p_o_s_i_t_i_o_n_a_l _p_a_r_a_m_e_t_e_r_s.

If no  corresponding parameter is given on  the command line, the
shell  substitutes  the  null  string  for that  parameter.   For
example, if the script ffoorrmmaatt contains the following line:


        nroff -ms $1 >$1.out


then invoking ffoorrmmaatt with the command line:


        format mytext


invokes the  command nnrrooffff to format the  contents of mmyytteexxtt, and
writes the output  into file mmyytteexxtt.oouutt.  If, however, you invoke
this command with the command line


        format mytext yourtext


the script will format mmyytteexxtt but ignore yyoouurrtteexxtt altogether.

Reference  $*  represents all  command-line  arguments.  If,  for
example, we change the contents of script ffoorrmmaatt to read


        nroff -ms $* >$1.out


then the command


        format mytext yourtext


will invoke nnrrooffff to  format the contents of mmyytteexxtt and yyoouurrtteexxtt,
and write the output into file mmyytteexxtt.oouutt.

Commands  in a  script  can also  be  executed with  the .  (dot)
command.   It resembles  the kksshh command,  but the  current shell


COHERENT Lexicon                                           Page 8




ksh                          Command                          ksh



executes the script commands without creating a new subshell or a
new   environment;  therefore,   you   cannot  use   command-line
arguments.

***** Variables *****

Shell variables are names that can be assigned string values on a
command line, in the form


        _n_a_m_e=_v_a_l_u_e


The  name must  begin  with a  letter, and  can contain  letters,
digits,  and  underscores   `_'.   In  shell  input,  `$_n_a_m_e'  or
`${_n_a_m_e}' represents the value of the variable.  For example:


        TEXT=mytext

        nroff -ms $TEXT >$TEXT.out


Here,  kksshh expands  $TTEEXXTT before it  executes the  nnrrooffff command.
This technique is very useful in large, complex scripts: by using
variables, you  can change the behavior of  the script by editing
one  line,   rather  than  having  to   edit  numerous  variables
throughout the script.

Note that if an assignment precedes a command on the same command
line,  the effect  of the  assignment is  local to  that command;
otherwise, the effect is permanent.  For example,


        kp=one testproc


assigns variable  kkpp the value oonnee only for  the execution of the
script tteessttpprroocc.

kksshh sets the following variables by default:

#  The  number  of  actual  positional  parameters given  to  the
   current command.

@  The list of positional parameters ``$1 $2 ...''.

*  The list of positional parameters ``$1'' ``$2'' ...  (the same
   as `$@' unless some parameters are quoted).

-  Options  set in  the invocation  of  the shell  or by  the sseett
   command.

?  The exit status returned by the last command.



COHERENT Lexicon                                           Page 9




ksh                          Command                          ksh



!  The process number of the last command invoked with `&'.

$  The process number of the current shell.

***** Environmental Variables *****

kksshh references the following environmental variables:

CCWWDD     Current  working  directory: this  is  the  name  of  the
        directory in which you are now working.

EENNVV     If this variable  is set  at start-up, after  all pprrooffiillee
        files have been  executed, the expanded value  is used as
        the  shell's   start-up  file.    It  typically   defines
        functions and aliases.

FFCCEEDDIITT  This sets the editor used by the command ffcc.

HHOOMMEE    Initial  working  directory;  usually  specified  in  the
        password file /eettcc/ppaasssswwdd.

IIFFSS     Delimiters  for  tokens;  by   default  space,  tab,  and
        newline.

KKSSHH_VVEERRSSIIOONN
        The current version of the Korn shell that you are using.

MMAAIILL    Checked at intervals specified  by environmental variable
        MMAAIILLCCHHEECCKK. If  file  specified by  this  variable is  new
        since last checked,  the shell prints  ``You have mail.''
        on the  user's terminal.   If the  file has  increased in
        size since the  last check,  the shell prints  ``You have
        new mail.'' on the user's terminal.

MMAAIILLCCHHEECCKK
        Specifies the number of seconds  between checking for new
        mail.   If  not  specified,   MMAAIILLCCHHEECCKK  defaults  to  60
        seconds.

OOLLDDPPWWDD  The prior working directory, if any.

PPAATTHH    Colon-separated  list   of   directories   searched   for
        commands.

PPSS11     First prompt  string,  usually `$'.   Note  that in  this
        variable and  PPSS22,  kksshh  expands the  symbol  ! into  the
        current number  of the  command line.   For  example, the
        prompt kksshh !> prints the prompt kksshh _N_N>    with     every
        command, where _N_N  is the number of  the current command.
        This is useful when you have enabled the history feature,
        as described below.

PPSS22     Second prompt string, usually `>'.  kksshh prints it when it
        expects more input,  such as when  an open quotation-mark
        has been typed  but a  close quotation-mark has  not been


COHERENT Lexicon                                          Page 10




ksh                          Command                          ksh



        typed, or within a shell construct.

PPWWDD     The present working directory, i.e., the directory within
        which you are now working.

SSEECCOONNDDSS
        The  number  of  seconds  since  the  current  shell  was
        started.

SSHHEELLLL   The  full  path  name  of the  shell  that  you  are  now
        executing.

TTEERRMM    The name of  the type of  terminal you are  now using, as
        used  by   various   programs   for   reading  the   file
        /eettcc/tteerrmmccaapp.

TTIIMMEEZZOONNEE
        The current timezone you  are located in, as  set in your
        .pprrooffiillee.  This is an  interesting and powerful variable;
        see its entry in the Lexicon for details.

UUSSEERR    The login-identifier of the user, i.e., you.

The following special forms substitute parameters conditionally:

${_n_a_m_e-_t_o_k_e_n}
     Substitite  _n_a_m_e if  it  is set;  if it  is not,  substitute
     _t_o_k_e_n.

${_n_a_m_e=_t_o_k_e_n}
     Substitute _n_a_m_e  if it is set; if it  is not set, substitute
     _t_o_k_e_n and set _n_a_m_e to equal _t_o_k_e_n.

${_n_a_m_e+_t_o_k_e_n}
     Substitute _t_o_k_e_n if _n_a_m_e is set.

${_n_a_m_e?_t_o_k_e_n}
     Substitute _n_a_m_e if it is set;  if it is not, print _t_o_k_e_n and
     exit from the shell.

***** Command Output Substitution *****

kksshh can  use the output of  a command as shell  input (as command
arguments,  for  example)  by  enclosing  the  command  in  grave
characters ` `.   For  example,  to  list  the  contents  of  the
directories named in file ddiirrss, use the command


        ls -l `cat dirs`


***** Constructs *****

kksshh  lets  you  control the  execution  of  programs through  the
following  constructs.   It recognizes  a  construct  only if  it


COHERENT Lexicon                                          Page 11




ksh                          Command                          ksh



occurs unquoted  as the first  token of a  command.  This implies
that a separator must precede each reserved word in the following
constructs; for  example, newline or  `;' must precede  ddoo in the
ffoorr construct.

bbrreeaakk [_n]
     Exit from ffoorr,  uunnttiill, or wwhhiillee. If _n is  given, exit from _n
     levels.

ccaassee _t_o_k_e_n iinn [ _p_a_t_t_e_r_n [ | _p_a_t_t_e_r_n ] ...) _s_e_q_u_e_n_c_e;; ] ... eessaacc
     Check  _t_o_k_e_n  against  each  _p_a_t_t_e_r_n, and  execute  _s_e_q_u_e_n_c_e
     associated with the first matching _p_a_t_t_e_r_n.

ccoonnttiinnuuee [_n]
     Branch to the end of  the _nth enclosing ffoorr, uunnttiill, or wwhhiillee
     construct.

ffoorr _n_a_m_e [ iinn _t_o_k_e_n ... ] ddoo _s_e_q_u_e_n_c_e ddoonnee
     Execute  _s_e_q_u_e_n_c_e once  for each  _t_o_k_e_n. On  each iteration,
     _n_a_m_e takes the value of the  next _t_o_k_e_n. If the iinn clause is
     omitted,  $@ is  assumed.  For  example,  to list  all files
     ending with .cc:

             for i in *.c
             do
                     cat $i
             done


iiff _s_e_q_1 tthheenn _s_e_q_2 [ eelliiff _s_e_q_3 tthheenn _s_e_q_4 ] ... [ eellssee _s_e_q_5 ] ffii
     Execute _s_e_q_1.  If the exit status is  zero, execute _s_e_q_2; if
     not, execute the optional _s_e_q_3 if given.  If the exit status
     of _s_e_q_3 is zero, then execute  _s_e_q_4, and so on.  If the exit
     status of all tested sequences is nonzero, execute _s_e_q_5.

ttiimmee _s_e_q_u_e_n_c_e
     Time how  long it takes _s_e_q_u_e_n_c_e  to execute.  When _s_e_q_u_e_n_c_e
     has  finished  exeucting,  the  time  is  displayed  on  the
     standard output.

wwhhiillee _s_e_q_u_e_n_c_e_1 [ ddoo _s_e_q_u_e_n_c_e_2 ] ddoonnee
     Execute  _s_e_q_u_e_n_c_e_2 as  long  as the  execution of  _s_e_q_u_e_n_c_e_1
     results in an exit status of zero.

(_s_e_q_u_e_n_c_e)
     Execute _s_e_q_u_e_n_c_e within a subshell.  This allows _s_e_q_u_e_n_c_e to
     change the  current directory,  for example, and  not affect
     the enclosing environment.

{_s_e_q_u_e_n_c_e}
     Braces simply enclose a _s_e_q_u_e_n_c_e.

***** Built-in Commands *****

kksshh  executes  most  commands via  the  ffoorrkk  system call,  which


COHERENT Lexicon                                          Page 12




ksh                          Command                          ksh



creates a  new process.  See  the Lexicon articles  on ffoorrkk() and
eexxeecc  for details  on these  calls.  kksshh  also has  the following
commands built into itself.

. _s_c_r_i_p_t
     Read and execute commands from _s_c_r_i_p_t. Positional parameters
     are not allowed.   kksshh searches the directories named in the
     environmental variable PPAATTHH to find the given _s_c_r_i_p_t.

: [_t_o_k_e_n ...]
     A colon  `:' indicates a ``partial  comment''.  kksshh normally
     ignores all  commands on  a line  that begins with  a colon,
     except for redirection and such symbols as $, {, ?, etc.

#    A complete  comment: if # is the first  character on a line,
     kksshh ignores all text that follows on that line.

aalliiaass [-dd] [_n_a_m_e=_v_a_l_u_e ...]
     When called without  arguments, aalliiaass prints all aliases and
     their  values.  When  called with a  _n_a_m_e but  no associated
     value, then it prints the value of _n_a_m_e.  When called with a
     _n_a_m_e and _v_a_l_u_e combination, it associated _v_a_l_u_e with _n_a_m_e.

     For example, the command

             alias logout='exit'

     binds  the  token llooggoouutt  to  the  command eexxiitt:  hereafter,
     whenever you  type llooggoouutt,  it will be  as if you  typed the
     eexxiitt command.

     The -dd option creates an alias for a directory.

     kksshh has a number of aliases set by default.  See the section
     AAlliiaasseess, below, for details.

bbiinndd [-mm] [_k_e_y__s_e_q_u_e_n_c_e=_b_i_n_d_i_n_g__n_a_m_e ...]
     When called  without arguments, list the  current set of key
     bindings  for  MicroEMACS-style  editing of  command  lines.
     When  called  with   arguments,  bind  the  _k_e_y__s_e_q_u_e_n_c_e  to
     _b_i_n_d_i_n_g__n_a_m_e.

     For example, the command

             bind '^[^H'=delete-word-backward

     binds  the editing command  ddeelleettee-wwoorrdd-bbaacckkwwaarrdd to  the key
     sequence <eesscc><bbaacckkssppaaccee>.   Note that the  carat characters
     in  this  command   are  literally  that,  not  the  shell's
     representation of a literal <eesscc> or <bbaacckkssppaaccee> character.

     When  called  with   the  -mm  option,  bind  more  than  one
     _b_i_n_d_i_n_g__n_a_m_e to  a given _k_e_y__s_e_q_u_e_n_c_e.  This  lets you build
     keyboard macros,  to perform complex editing  tasks with one
     or two keystrokes.


COHERENT Lexicon                                          Page 13




ksh                          Command                          ksh




     See the section on CCoommmmaanndd-lliinnee EEddiittiinngg, below, for details.

bbuuiillttiinn _c_o_m_m_a_n_d
     Execute _c_o_m_m_a_n_d as a built-in command.

ccdd _d_i_r
     Change  the working  directory  to _d_i_r.  If  no argument  is
     given,  change   to  the  home  directory   as  set  by  the
     environmental variable  HHOOMMEE. When invoked,  it also changes
     the environmental variables PPWWDD and OOLLDDPPWWDD.

     Using a  hyphen `-' as the argument causes  kksshh to change to
     the  previous directory,  i.e., the  one indicated  by shell
     variable OOLLDDPPWWDD. In  effect, this swaps OOLLDDPPWWDD and PPWWDD, thus
     allowing  you to  flop  back and  forth  easily between  two
     directories.

eecchhoo _t_o_k_e_n ...
     Echo  _t_o_k_e_n  onto the  standard  output.   kksshh replaces  the
     command eecchhoo with the alias eecchhoo='pprriinntt'.

eevvaall [_t_o_k_e_n ...]
     Evaluate each _t_o_k_e_n and treat the result as shell input.

eexxeecc [_c_o_m_m_a_n_d]
     Execute _c_o_m_m_a_n_d directly  rather than as a subprocess.  This
     terminates the current shell.

eexxiitt [_s_t_a_t_u_s]
     Set  the exit  status to _s_t_a_t_u_s,  if given,  then terminate;
     otherwise, the previous status is used.

eexxppoorrtt [_n_a_m_e ...]
     kksshh  executes  each  command  in  an _e_n_v_i_r_o_n_m_e_n_t,  which  is
     essentially a set  of shell variable names and corresponding
     string values.  It inherits an environment when invoked, and
     normally it  passes the same environment  to each command it
     invokes.  eexxppoorrtt  specifies that  the shell should  pass the
     modified  value of  each given  _n_a_m_e  to the  environment of
     subsequent commands.  When  no _n_a_m_e is given, kksshh prints the
     name of each variable marked for export.

ffcc [-ll] [-nn] [_f_i_r_s_t [_l_a_s_t]]
     Draw  the previously  executed commands  _f_i_r_s_t  through _l_a_s_t
     back  for manipulation  and possible  execution.   _f_i_r_s_t and
     _l_a_s_t can  be referenced either by  their history numbers, or
     by  a string  with  which the  command  in question  begins.
     Normally,  the  commands  are  pulled  into  an  editor  for
     manipulation before they are executed; the editor is defined
     by  the environmental  variable FFCCEEDDIITT  (default,  eedd).  The
     commands in  question are executed as soon  as you exit from
     the editor.   Option -ll lists the  command(s) on ssttddoouutt, and
     so suppresses  the editing feature.  Option  -nn inhibits the
     default history numbers.


COHERENT Lexicon                                          Page 14




ksh                          Command                          ksh




ffcc -ss [_o_l_d=_n_e_w] [_c_o_m_m_a_n_d]
     Re-execute _c_o_m_m_a_n_d after substituting string _n_e_w for _o_l_d.

ggeettooppttss _o_p_t_s_t_r_i_n_g _n_a_m_e [_a_r_g ...]
     Parse  the _a_r_gs  to See  the Lexicon  entry for  ggeettooppttss for
     details.

hhaasshh [-rr] [_n_a_m_e ...]
     When called without  arguments, hhaasshh lists the path names of
     all hashed  commands.  When called  with _n_a_m_e hhaasshh  check to
     see if it is an executable command, and if so adds it to the
     shell's hash list.  The -rr option removes _n_a_m_e from the hash
     list.

kkiillll [-ll] [_s_i_g_n_a_l] _p_r_o_c_e_s_s ...
     Send _s_i_g_n_a_l  to _p_r_o_c_e_s_s. The  default signal is  TTEERRMM, which
     terminates the process.  _s_i_g_n_a_l  may either be a number or a
     mnemonic as #ddeeffiinneed  in header file <ssiiggnnaall.hh>. When called
     with the  -ll option,  it lists  all known types  of signals.
     See the Lexicon entry for kkiillll for details.

lleett [_e_x_p_r_e_s_s_i_o_n]
     Evaluate  each  _e_x_p_r_e_s_s_i_o_n.  This  command returns  zero  if
     _e_x_p_r_e_s_s_i_o_n evaluates to  non-zero (i.e., fails), and returns
     non-zero if  it evalutes to zero  (i.e., succeeds).  This is
     useful for evaluating  expressions before actually executing
     them.

pprriinntt [-nnrreeuu_n] [_a_r_g_u_m_e_n_t ...]
     Print  each _a_r_g_u_m_e_n_t  on the  standard output,  separated by
     spaces and terminated  with a newline.  Option -nn suppresses
     printing of  the newline.  Option -uu_n  redirects output from
     the standard output to file descriptor _n.

     Note that each _a_r_g_u_m_e_n_t can contain the following standard C
     escape characters:  \bb, \ff,  \nn, \rr,  \vv, and \###.  See the
     Lexicon article  on CC LLaanngguuaaggee for  details each character's
     meaning.  The  option -rr inhibits  this feature, and  the -ee
     option re-enables it.

rreeaadd _n_a_m_e ...
     Read a line from the standard input and assign each token of
     the input  to the corresponding shell  variable _n_a_m_e. If the
     input contains  fewer tokens than the  _n_a_m_e list, assign the
     null string to  extra variables.  If the input contains more
     tokens, assign the last _n_a_m_e the remainder of the input.

rreeaaddoonnllyy [_n_a_m_e ...]
     Mark  each  shell variable  _n_a_m_e  as  a read-only  variable.
     Subsequent  assignments to read-only  variables will  not be
     permitted.  With  no arguments, print the  name and value of
     each read-only variable.




COHERENT Lexicon                                          Page 15




ksh                          Command                          ksh



rreettuurrnn [_s_t_a_t_u_s]
     Return _s_t_a_t_u_s to the parent process.

sseett [-aaeeffhhkkmmnnuuvvxx [-oo _k_e_y_w_o_r_d] [_n_a_m_e ...] ]
     Set listed flag.   The -oo option sets _k_e_y_w_o_r_d, where _k_e_y_w_o_r_d
     is a shell option.

     When used  with one or  more _n_a_m_e_s, this  command sets shell
     variables _n_a_m_e to  values of positional parameters beginning
     with $11.

     For example, the command

             set -h -o emacs ignoreeof

     performs the  following: turns on hashing  for all commands,
     turns  on MicroEMACS-style  command-line editing,  and turns
     off exiting  upon EOF (that  is, you must type  eexxiitt to exit
     from the  shell).  sseett  commands are especially  useful when
     embedded in  your .pprrooffiillee, where they  can customize kksshh to
     your preferences.

     For details of this command, see its Lexicon entry.

sshhiifftt
     Rename positional parameter 11 to current value of $22, and so
     on.

tteesstt [_o_p_t_i_o_n] [_e_x_p_r_e_s_s_i_o_n]
     Check _e_x_p_r_e_s_s_i_o_n for condition  _o_p_t_i_o_n. This is a useful and
     complex command, with  more options than can be listed here.
     See its Lexicon entry for details.

ttiimmeess
     Print on  the standard output  a summary of  processing time
     used by the current shell and all of its child processes.

ttrraapp [_c_o_m_m_a_n_d] [_n ...]
     Execute  _c_o_m_m_a_n_d if  kksshh receives  signal  _n. If  _c_o_m_m_a_n_d is
     omitted,  reset  traps  to  original  values.  To  ignore  a
     signal, pass  null string as  _c_o_m_m_a_n_d. With _n  zero, execute
     _c_o_m_m_a_n_d when the  shell exits.  With no arguments, print the
     current trap settings.

ttyyppeesseett [-ffiirrxx] [+ffiirrxx] [_n_a_m_e [=_v_a_l_u_e] ... ]
     When  called without  an  argument, this  command lists  all
     variables and their attributes.

     When called with an option  but without a _n_a_m_e, it lists all
     variables that have the specified attribute; - tells ttyyppeesseett
     to list the value of each variable and + tells it not to.

     When called  with one  or more _n_a_m_e_s,  it gives _n_a_m_e  to the
     listed  attribute.   If _n_a_m_e  is  associated  with a  _v_a_l_u_e,
     ttyyppeesseett also assigns the _v_a_l_u_e to it.


COHERENT Lexicon                                          Page 16




ksh                          Command                          ksh




     ttyyppeesseett recognizes the following attributes:

             -ii      Store variable's value as an integer
             -ff      List function instead of variable
             -rr      Make the variable read-only
             -xx      Export variable to the environment

uummaasskk [_n_n_n]
     Set user file creation mask to _n_n_n. If no argument is given,
     print the current file creation mask.

uunnaalliiaass [-dd] _n_a_m_e ...
     Remove the  alias for each _n_a_m_e. The  -dd option unaliases an
     alias for a directory.

wwaaiitt [_p_i_d]
     Hold  execution  of   further  commands  until  process  _p_i_d
     terminates.   If   _p_i_d  is  omitted,  wait   for  all  child
     processes.  If no children are active, this command finishes
     immediately.

wwhheennccee [-vv] _n_a_m_e ...
     List the type of command for each _n_a_m_e. When called with the
     -vv option, also list functions and aliases.

***** Aliases *****

kksshh implements  as aliases a number of commands  that sshh calls as
separate executable programs.  The eecchhoo alias, for instance, does
everything that  /bbiinn/eecchhoo does, but kksshh does  not have to ffoorrkk()
and eexxeecc() simply to echo a token.  Other aliases, like ppwwdd, work
by  printing  the  contents  of  shell  variables.   The  command
/bbiinn/ppwwdd still  works should you prefer it,  but you must request
it by  its full  path name  should you not  wish to use  the much
faster alias version.

kksshh sets the following aliases  by default.  If you wish, you can
use the  built-in command uunnaalliiaass to  make one or all  of them go
away.

        eecchhoo=pprriinntt
        ffaallssee=lleett
        ffuunnccttiioonnss=ttyyppeesseett -ff
        hhiissttoorryy=ffcc -ll
        iinntteeggeerr=ttyyppeesseett -ii
        llooggiinn=eexxeecc llooggiinn
        nneewwggrrpp=eexxeecc nneewwggrrpp
        ppwwdd=pprriinntt -rr $PPWWDD
        rr=ffcc -ss
        ttrruuee=:
        ttyyppee=wwhheennccee -vv





COHERENT Lexicon                                          Page 17




ksh                          Command                          ksh



***** Job Control *****

kksshh lets  you manipulate and monitor background  jobs via its _j_o_b
_c_o_n_t_r_o_l commands.

The following commands manipulate background jobs:

jjoobbss Display information about  all controlled jobs.  Information
     is in the following format:

             %_n_u_m [+-] _p_i_d _s_t_a_t_u_s _c_o_m_m_a_n_d

     where  _n_u_m indicates  the  job number,    `+' indicates  the
     current  job, `-'  indicates the  previous  job, _p_i_d  is the
     job's process identifier, _s_t_a_t_u_s shows the status of the job
     (e.g., Running,  Done, Killed),  and _c_o_m_m_a_n_d is  the command
     description.  Note  that kksshh only checks  for changes in job
     status when waiting for a command to complete.

kkiillll [-_s_i_g_n_a_l] _p_i_d ...
     Described above.

wwaaiitt [_p_i_d]
     Hold  execution  of   further  commands  until  process  _p_i_d
     terminates.  See its Lexicon entry for details.

The following `%' syntax can be used with the above commands:

%+   Select the current job.

%-   Select the previous job.

%_n_u_m Select the job with job number _n_u_m.

%_s_t_r_i_n_g
     Select the  most recently  invoked job whose  command begins
     with _s_t_r_i_n_g.

%?_s_t_r_i_n_g
     Select the most  recently invoked job whose command contains
     _s_t_r_i_n_g.

***** Command-line Editing *****

One of the most useful features of kksshh is its ability to remember
commands that  you have typed previously.   You can interactively
edit previously issued commands and re-issue them with just a few
keystrokes.

You  can recall  commands  and edit  them using  the ffcc  command,
described  above.   kksshh,  however,  also  has  built  into  it  a
MicroEMACS editing feature that lets you recall and edit commands
using MicroEMACS-style editing  commands.  When you have finished
editing,  simply typing  <eenntteerr> dispatches  the command  for re-
execution.


COHERENT Lexicon                                          Page 18




ksh                          Command                          ksh




To turn on MicroEMACS editing, use the command


        set -o emacs


The following  table gives each  editing command and  its default
keybinding.   Note that  you  can replace  any  of the  following
keybindings by  using the  bbiinndd command, described  above.  Note,
too, that not every command has a default keybinding.  Those that
do not have one are marked ``None''.

aabboorrtt (<ccttrrll-GG>)
     Abort the current input line or function.

aauuttoo-iinnsseerrtt
     Insert text into the  command line.  This is the default for
     almost every key.

bbaacckkwwaarrdd-cchhaarr (<ccttrrll-BB>)
     Move the cursor one character to the left.

bbaacckkwwaarrdd-wwoorrdd (<eesscc>BB)
     Move the cursor one word to  the left.  A wwoorrdd is defined as
     any  cluster   of  characters  delineated  by   any  of  the
     characters  named  in  the  environmental variable  IIFFSS:  by
     default, <ssppaaccee>, <ttaabb>, and <nneewwlliinnee>.

bbeeggiinnnniinngg-ooff-lliinnee (<ccttrrll-AA>)
     Move  the  cursor   to  the  leftmost  position  (i.e.,  the
     beginning) of the line.

ccoommpplleettee (<eesscc><eesscc>)
     Complete as much as is  unique of the hashed command name or
     file name  in which the cursor is  positioned.  If no unique
     command or  file name is  found, kksshh beeps.   Note that this
     command does nothing unless you have used the sseett command to
     turn on hashing.

ccoommpplleettee-ccoommmmaanndd (<ccttrrll-XX><eesscc>)
     Automatically complete  as much as  is unique of  the hashed
     command name.  Like the ccoommpplleettee command, above, except that
     file names are not expanded.

ccoommpplleettee-ffiillee (<ccttrrll-XX><ccttrrll-XX>)
     Automatically  complete as  much as  is  unique of  the file
     name.   Like  the   ccoommpplleettee  command,  above,  except  that
     commands are not expanded.

ddeelleettee-cchhaarr-bbaacckkwwaarrdd (<ccttrrll-HH>)
     Delete the character to  the left of the cursor.  Shift text
     to the left to fill the gap left by the deleted character.




COHERENT Lexicon                                          Page 19




ksh                          Command                          ksh



ddeelleettee-cchhaarr-ffoorrwwaarrdd (<ccttrrll-DD>)
     Delete the  character upon  which the cursor  is positioned.
     Shift text to  the left to fill the gap  left by the deleted
     character.

ddeelleettee-wwoorrdd-bbaacckkwwaarrdd (<ccttrrll-WW>)
     Delete the  word to the  left of the cursor.   Shift text to
     the left to fill the gap left by the deleted word.

ddeelleettee-wwoorrdd-ffoorrwwaarrdd (<eesscc>DD)
     Delete the  word to the right of the  cursor.  Shift text to
     the left to fill the gap left by the deleted word.

ddoowwnn-hhiissttoorryy (<ccttrrll-NN>)
     Scroll to the next command in the history buffer, if any.

eenndd-ooff-lliinnee (<ccttrrll-EE>)
     Move the cursor to the rightmost position (i.e., the end) of
     the line.

eeoott (<ccttrrll-_>)
     Send  an EOT  (end  of transmission)  signal  to the  shell.
     Normally,  this is  sent  by <ccttrrll-DD>,  but MicroEMACS  mode
     binds this keystroke to an editing command.

ffoorrwwaarrdd-cchhaarr (<ccttrrll-FF>)
     Move the cursor one character to the right.

ffoorrwwaarrdd-wwoorrdd (<eesscc>FF)
     Move the cursor one word to the right.

kkiillll-lliinnee (<ccttrrll-UU>)
     Delete (i.e., erase) this entire input line.

kkiillll-ttoo-eeooll (<ccttrrll-KK>)
     Kill the  input line from where the  cursor is positioned to
     the end of the line.

lliisstt (<eesscc>?)
     Display  a sorted  listed of  all  hashed commands  and file
     names that have been entered so far, and so lists the tokens
     that can  be expanded with the  ccoommpplleettee commands, described
     above.

lliisstt-ccoommmmaanndd (<ccttrrll-XX>?)
     List all hashed commands.

lliisstt-ffiillee (none)
     List all files used in hashed commands so far.

nneewwlliinnee (<ccttrrll-JJ> or <ccttrrll-MM>)
     Dispatch the  current line to the  shell for execution.  The
     cursor need not  be at the beginning or end  of the line for
     this command to work correctly.



COHERENT Lexicon                                          Page 20




ksh                          Command                          ksh



pprreeffiixx-11 (<eesscc>)
     Introduce a two-character command sequence.

pprreeffiixx-22 (<ccttrrll-XX>)
     Introduce a two-character command sequence.

qquuoottee (<ccttrrll-^>)
     Read the  following character  literally, rather than  as an
     editing command.

rreeddrraaww (<ccttrrll-LL>)
     Redisplay the prompt  and the current command line.  This is
     useful if  the line is garbled due to,  say, line noise when
     you are using a modem.

sseeaarrcchh-cchhaarraacctteerr (<ccttrrll-]>)
     Search  forward in  the current  command  line for  the next
     character typed.

sseeaarrcchh-hhiissttoorryy (<ccttrrll-RR>)
     Enter incremental-search  mode and search  backwards through
     the history buffer.   aabboorrtt aborts search and returns you to
     the  line  from  which  you  began  the search;  <eesscc>  ends
     searching and leaves you in the current line.

ssttuuffff (none)
     Take a  character that  is bound  to an editing  command and
     ``stuff'' it back into the terminal input, so it can receive
     special treatment by the terminal handler.

ssttuuffff-rreesseett (none)
     ``Stuffs'' a character, then aborts input.

ttrraannssppoossee-cchhaarrss (<ccttrrll-TT>)
     Swap the  character the cursor in on,  with the character to
     its left.

uupp-hhiissttoorryy (<ccttrrll-PP>)
     Move to the previous line in the history buffer (if any).

yyaannkk (<ccttrrll-YY>)
     Insert the  most recently killed text  back into the command
     string, at the point where the cursor is positioned.

yyaannkk-ppoopp (<eesscc>YY)
     Yank a  string, then replace  it within the  ``yank'' buffer
     with the next most previously killed string.

***** Example *****

The  following C  code  creates a  program  called sspplluurrtt.cc.   It
demonstrates  numbered redirection  of  kksshh, by  writing to  five
streams without opening them.  Compile it with the command:




COHERENT Lexicon                                          Page 21




ksh                          Command                          ksh




        cc -o splurt splurt.c


To call it from the command line, you could type a command of the
form:


        splurt  3> splurt3 4> splurt4 5> splurt5 6> splurt6 7> splurt7


This will redirect the sspplluurrtt's output into files sspplluurrtt33 through
sspplluurrtt77.


#include <stdio.h>
main()
{
        int i;
        char buf[50];



        for(i = 3; i < 8; i++) {
                sprintf(buf, "For fd %d\n", i);
                write(i, buf, strlen(buf));
        }
}


***** Files *****

/eettcc/pprrooffiillee -- System-wide initial commands
$HHOOMMEE/.pprrooffiillee -- User-specific initial commands
/ddeevv/nnuullll -- For background input

***** See Also *****

bbiinndd,  ccoommmmaannddss,  dduupp(), eennvviirroonn,  eexxeecc,  ffoorrkk(), ggeettooppttss,  jjoobbss,
kkiillll, llooggiinn, nneewwggrrpp, sseett, sshh, ssiiggnnaall(), tteesstt, wwaaiitt
_I_n_t_r_o_d_u_c_t_i_o_n _t_o _s_h, _t_h_e _B_o_u_r_n_e _S_h_e_l_l, tutorial

***** Notes *****

This version of  kksshh offers a subset of the  features of the Korn
shell  shipped  with UNIX  System  V.2.  It  does  _n_o_t offer  the
following features:

-> vvii-style command-line editing.

-> Command ffcc -ee.

-> Variables RRAANNDDOOMM and PPPPIIDD.




COHERENT Lexicon                                          Page 22




ksh                          Command                          ksh



-> Variable arrays.

-> Variable attributes other than integers.

The Mark  Williams version of  kksshh is based  on the public-domain
version of the Korn shell, which  in turn is based on the public-
domain  version of  the seventh edition  Bourne shell  written by
Charles Forsyth  and modified by Eric  Gisin, Ron Natalie, Arnold
Robbins, Doug Gwyn, and Erik Baalbergen.
















































COHERENT Lexicon                                          Page 23



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.