Metropoli BBS
VIEWER: ksh.man MODE: TEXT (ASCII)


KSH(1)                    User commands                    KSH(1)


NNAAMMEE
       ksh - Public domain Korn shell

SSYYNNOOPPSSIISS
       kksshh [++--aabbCCeeffhhiikkmmnnpprrssuuvvxxXX] [++--oo _o_p_t_i_o_n] [ [ --cc _c_o_m_m_a_n_d_-
       _s_t_r_i_n_g [_c_o_m_m_a_n_d_-_n_a_m_e] | --ss | _f_i_l_e ] [_a_r_g_u_m_e_n_t ...] ]

DDEESSCCRRIIPPTTIIOONN
       kksshh is a command interpreter that  is  intended  for  both
       interactive and shell script use.  Its command language is
       a superset of the _s_h(1) shell language.

   SShheellll SSttaarrttuupp
       The following options can be specified only on the command
       line:

       --cc _c_o_m_m_a_n_d_-_s_t_r_i_n_g
              the shell executes the command(s) contained in _c_o_m_-
              _m_a_n_d_-_s_t_r_i_n_g

       --ii     interactive mode -- see below

       --ss     the shell reads commands from standard  input;  all
              non-option arguments are positional parameters

       --rr     restricted mode -- see below

       In addition to the above, the options described in the sseett
       builtin command can also be used on the command line.

       If neither the --cc nor the --ss options  are  specified,  the
       first non-option argument specifies the name of a file the
       shell reads commands from;  if  there  are  no  non-option
       arguments,  the  shell reads commands from standard input.
       The name of the shell  (i.e.,  the  contents  of  the  $$00)
       parameter  is  determined  as follows: if the --cc option is
       used and there is a non-option argument, it is used as the
       name;  if commands are being read from a file, the file is
       used as the name; otherwise the name the shell was  called
       with (i.e., argv[0]) is used.

       A shell is _i_n_t_e_r_a_c_t_i_v_e if the --ii option is used or if both
       standard input and standard error are attached to  a  tty.
       An  interactive  shell  has job control enabled (if avail-
       able), ignores the INT, QUIT and TERM signals, and  prints
       prompts before reading input (see PPSS11 and PPSS22 parameters).
       For non-interactive shells, the ttrraacckkaallll option is  on  by
       default (see sseett command below).

       A  shell  is  rreessttrriicctteedd  if  the  --rr option is used or if
       either the basename of the name the shell is invoked  with
       or the SSHHEELLLL parameter match the pattern *r*sh (e.g., rsh,
       rksh, rpdksh, etc.).  The following restrictions come into
       effect  after  the  shell  processes  any profile and $$EENNVV



                        November 28, 1994                       1





KSH(1)                    User commands                    KSH(1)


       files:
         +o    the ccdd command is disabled
         +o    the SSHHEELLLL, EENNVV and PPAATTHH parameters can't be changed
         +o    command  names  can't be specified with absolute or
              relative paths
         +o    the --pp option of the ccoommmmaanndd builtin can't be used
         +o    redirections that create files can't be used (i.e.,
              >>, >>||, >>>>, <<>>)

       A  shell  is pprriivviilleeggeedd if the --pp option is used or if the
       real user-id or group-id  does  not  match  the  effective
       user-id  or group-id (see _g_e_t_u_i_d(2), _g_e_t_g_i_d(2)).  A privi-
       leged shell does not process $HOME/.profile  nor  the  EENNVV
       parameter  (see below), instead the file /etc/suid_profile
       is processed.  Clearing the privileged option  causes  the
       shell  to set its effective user-id (group-id) to its real
       user-id (group-id).

       If the basename of the  name  the  shell  is  called  with
       (i.e.,  argv[0]) starts with --, the shell is assumed to be
       a login shell and the shell reads and  executes  the  con-
       tents of //eettcc//pprrooffiillee and $$HHOOMMEE//..pprrooffiillee if they exist and
       are readable.

       If the EENNVV parameter is set when the shell starts (or,  in
       the  case  of  login  shells,  after any profiles are pro-
       cessed), its value is subjected to parameter, command  and
       arithmetic substitution and the resulting file (if any) is
       read and executed.

       The exit status of the shell is 127 if  the  command  file
       specified on the command line could not be opened, or non-
       zero if a fatal syntax error occurred during the execution
       of  a  script.   In  the absence of fatal errors, the exit
       status is that of the last command executed, or  zero,  if
       no command is executed.

   CCoommmmaanndd SSyynnttaaxx
       The  shell  begins  parsing  its input by breaking it into
       _w_o_r_ds.  Words, which  are  sequences  of  characters,  are
       delimited  by  unquoted _w_h_i_t_e_-_s_p_a_c_e characters (space, tab
       and newline) or _m_e_t_a_-_c_h_a_r_a_c_t_e_r_s (<<, >>, ||, ;;, &&, (( and  ))).
       Aside  from delimiting words, spaces and tabs are ignored,
       while  newlines  usually  delimit  commands.   The   meta-
       characters  are  used in building the following tokens: <<,
       <<&&, <<<<, >>, >>&&, >>>>, etc. used to specify redirections  (see
       Input/Output   Redirection   below);   ||  used  to  create
       pipelines;  ||&&  used  to  create  co-processes  (see   Co-
       Processes  below);  ;; used to separate commands; && used to
       create asynchronous pipelines; &&&& and |||| used  to  specify
       conditional  execution; ;;;; used in ccaassee statements; (( .. ))
       used to start subshells; and lastly, (((( ..  ))))  which  are
       used in arithmetic expressions;




                        November 28, 1994                       2





KSH(1)                    User commands                    KSH(1)


       White-space and meta-characters can be quoted individually
       using backslash (\\), or in groups using double ("") or sin-
       gle  ('')  quotes.   Note that the following characters are
       also treated specially by the shell and must be quoted  if
       they  are to represent themselves: \\, "", '', ##, $$, ``, ~~, {{,
       }}, **, ?? and [[.  The first three of  these  are  the  above
       mentioned  quoting  characters  (see Quoting below); ##, if
       used at the beginning of a word, introduces a  comment  --
       everything  after  the  ##  up  to  the  nearest newline is
       ignored; $$ is used to  introduce  parameter,  command  and
       arithmetic   substitutions  (see  Substitution  below);  ``
       introduces an old-style command substitution (see  Substi-
       tution  below);  ~~ begins a directory expansion (see Tilde
       Expansion below); {{ and }} delimit  _c_s_h(1)  style  alterna-
       tions  (see Brace Expansion below); and, finally, **, ?? and
       [[ are used in file name generation (see File Name Patterns
       below).

       As words and tokens are parsed, the shell builds commands,
       of which there are two basic types: _s_i_m_p_l_e_-_c_o_m_m_a_n_d_s, typi-
       cally  programs  that are executed, and _c_o_m_p_o_u_n_d_-_c_o_m_m_a_n_d_s,
       such as ffoorr and iiff  statements,  grouping  constructs  and
       function definitions.

       A simple-command consists of some combination of parameter
       assignments (see Parameters below), input/output  redirec-
       tions  (see  Input/Output Redirections below), and command
       words; the only restriction is that parameter  assignments
       come before any command words.  The command words, if any,
       define the command that is to be executed  and  its  argu-
       ments.   The  command  may  be a shell built-in command, a
       function or an _e_x_t_e_r_n_a_l _c_o_m_m_a_n_d,  i.e.,  a  separate  exe-
       cutable file that is located using the PPAATTHH parameter (see
       Command Execution below).   Note  that  all  command  con-
       structs  have  an _e_x_i_t _s_t_a_t_u_s: for external commands, this
       is related to the status returned  by  _w_a_i_t(2);  the  exit
       status  of  other  command  constructs (built-in commands,
       functions, compound-commands, pipelines, lists, etc.)  are
       all  well defined and are described where the construct is
       described.  The exit status of a command  consisting  only
       of  parameter assignments is that of the last command sub-
       stitution performed during  the  parameter  assignment  or
       zero if there were no command substitutions.

       Commands can be chained together using the || token to form
       _p_i_p_e_l_i_n_e_s, in which the standard output  of  each  command
       but  the last is piped (see _p_i_p_e(2)) to the standard input
       of the following command.  The exit status of  a  pipeline
       is  that  of its last command.  A pipeline may be prefixed
       by the !! reserved word which causes the exit status of the
       pipeline  to  be  logically  complemented: if the original
       status was 0 the complemented status will be 1, and if the
       original  status  was  not 0, then the complemented status
       will be 0.



                        November 28, 1994                       3





KSH(1)                    User commands                    KSH(1)


       _L_i_s_t_s of commands can be created by  separating  pipelines
       by  any of the following tokens: &&&&, ||||, &&, ||&& and ;;.  The
       first two are for conditional execution: _c_m_d_1 &&&& _c_m_d_2 exe-
       cutes  _c_m_d_2 only if the exit status of _c_m_d_1 is zero; |||| is
       the opposite -- _c_m_d_2 is executed only if the  exit  status
       of  _c_m_d_1  is  non-zero.   &&&&  and |||| have equal precedence
       which is higher than that of &&, ||&& and ;;, which also  have
       equal  precedence.   The && token causes the preceding com-
       mand to be executed asynchronously,  that  is,  the  shell
       starts  the  command, but does not wait for it to complete
       (the shell does keep track of the status  of  asynchronous
       commands  -- see Job Control below).  When an asynchronous
       command is started when job control is disabled (i.e.,  in
       most scripts), the command is started with signals INT and
       QUIT ignored and  with  input  redirected  from  /dev/null
       (however,  redirections specified in the asynchronous com-
       mand have precedence).   The  ||&&  operator  starts  a  _c_o_-
       _p_r_o_c_e_s_s which is special kind of asynchronous process (see
       Co-Processes below).  Note that a command must follow  the
       &&&& and |||| operators, while a command need not follow &&, ||&&
       and ;;.  The exit status of a list is that of the last com-
       mand  executed,  with the exception of asynchronous lists,
       for which the exit status is 0.

       Compound commands are created used the following  reserved
       words  --  these  words  are  only  recognized if they are
       unquoted and if they are used as the first word of a  com-
       mand  (i.e.,  they  can't be preceded by parameter assign-
       ments or redirections):
                  ccaassee   eellssee   ffuunnccttiioonn   tthheenn    !!
                  ddoo     eessaacc   iiff         ttiimmee    [[[[
                  ddoonnee   ffii     iinn         uunnttiill   {{
                  eelliiff   ffoorr    sseelleecctt     wwhhiillee   }}
       NNoottee:: Some shells (but not ksh) execute control  structure
       commands  in  a  subshell  when  one or more of their file
       descriptors are redirected,  so  any  environment  changes
       inside  them may fail.  To be portable, the eexxeecc statement
       should be used instead to redirect file descriptors before
       the control structure.

       (( _l_i_s_t ))
              Execute  _l_i_s_t  in a subshell.  There is no implicit
              way to pass environment  changes  from  a  subshell
              back to its parent.

       {{ _l_i_s_t }}
              Compound  construct; _l_i_s_t is executed, but not in a
              subshell.   Note  that  {{  and  }}  are  not   meta-
              characters and thus must be distinct words.

       ccaassee _w_o_r_d iinn [ [((] _p_a_t_t_e_r_n [|| _p_a_t_t_e_r_n] ... )) _l_i_s_t ;;;; ] ...
              eessaacc
              The ccaassee statement attempts to match  _w_o_r_d  against
              the  specified  _p_a_t_t_e_r_ns;  the _l_i_s_t associated with



                        November 28, 1994                       4





KSH(1)                    User commands                    KSH(1)


              the first successfully matched pattern is executed.
              Patterns  used  in  ccaassee statements are the same as
              those used for file name patterns except  that  the
              restrictions  regarding  .. and // are dropped.  Note
              that any unquoted space before and after a  pattern
              is  stripped;  any  space  with  a  pattern must be
              quoted.  Both the word and the patterns are subject
              to  parameter, command, and arithmetic substitution
              as well as tilde substitution.  The exit status  of
              a  ccaassee  statement is that of the executed _l_i_s_t; if
              no _l_i_s_t is executed, the exit status is zero.

       ffoorr _n_a_m_e [ iinn _w_o_r_d ... _t_e_r_m ] ddoo _l_i_s_t ddoonnee
              where _t_e_r_m is either a newline or a  ;;.   For  each
              _w_o_r_d in the specified word list, the parameter _n_a_m_e
              is set to the word and _l_i_s_t is executed.  If iinn  is
              not  used  to  specify  a word list, the positional
              parameters ($$11, $$22, etc.) are  used  instead.   The
              exit  status  of  a  ffoorr statement is the last exit
              status of _l_i_s_t; if _l_i_s_t is never executed, the exit
              status is zero.

       iiff _l_i_s_t tthheenn _l_i_s_t [eelliiff _l_i_s_t tthheenn _l_i_s_t] ... [eellssee _l_i_s_t] ffii
              If the exit status of the first _l_i_s_t is  zero,  the
              second _l_i_s_t is executed; otherwise the _l_i_s_t follow-
              ing the eelliiff, if any, is executed with similar con-
              sequences.   If  all the lists following the iiff and
              eelliiffs fail (i.e., exit with non-zero  status),  the
              _l_i_s_t following the eellssee is executed.  The exit sta-
              tus of an iiff statement is that  of  non-conditional
              _l_i_s_t  that  is executed; if no non-conditional _l_i_s_t
              is executed, the exit status is zero.

       sseelleecctt _n_a_m_e [ iinn _w_o_r_d ... _t_e_r_m ] ddoo _l_i_s_t ddoonnee
              where _t_e_r_m is either a newline or a ;;.  The  sseelleecctt
              statement  provides an automatic method of present-
              ing the user with a menu and selecting from it.  An
              enumerated  list of the specified _w_o_r_d_s are printed
              on standard error, followed by a prompt (PPSS33,  nor-
              mally `##?? ').  A number corresponding to one of the
              enumerated words is then read from standard  input,
              _n_a_m_e  is  set  to the selected word (or is unset if
              the selection is not valid), RREEPPLLYY is set  to  what
              was  read,  and  _l_i_s_t is executed.  This process is
              repeated until an end-of-file is read, an interrupt
              is received or a break statement is executed inside
              the loop.  If iinn _w_o_r_d ......  is  omitted,  the  posi-
              tional  parameters  are  used (i.e., $$@@).  The exit
              status of a sseelleecctt statement is  zero  if  a  break
              statement is used to exit the loop, non-zero other-
              wise.

       uunnttiill _l_i_s_t ddoo _l_i_s_t ddoonnee
              This works like wwhhiillee,  except  that  the  body  is



                        November 28, 1994                       5





KSH(1)                    User commands                    KSH(1)


              executed  only  while  the exit status of the first
              _l_i_s_t is non-zero.

       wwhhiillee _l_i_s_t ddoo _l_i_s_t ddoonnee
              A wwhhiillee is a prechecked loop.  Its body is executed
              as  often  as  the exit status of the first _l_i_s_t is
              zero.  The exit status of a wwhhiillee statement is  the
              last  exit  status  of  the _l_i_s_t in the body of the
              loop; if the body is not executed, the exit  status
              is zero.

       ffuunnccttiioonn _n_a_m_e {{ _l_i_s_t }}
              Defines  the  function  _n_a_m_e.  See Functions below.
              Note that redirections specified after  a  function
              definition  are  performed whenever the function is
              executed, not when the function definition is  exe-
              cuted.

       _n_a_m_e (()) _c_o_m_m_a_n_d
              Mostly  the same as ffuunnccttiioonn.  See Functions below.

       (((( _e_x_p_r_e_s_s_i_o_n ))))
              The arithmetic expression _e_x_p_r_e_s_s_i_o_n is  evaluated;
              equivalent  to  lleett  ""_e_x_p_r_e_s_s_i_o_n"".   See Arithmetic
              Expressions and the lleett command below.

       [[[[ _e_x_p_r_e_s_s_i_o_n ]]]]
              Similar to the tteesstt and [[ ... ]] commands (described
              later), with the following exceptions:
                +o    Field splitting and file name generation are
                     not performed on arguments.
                +o    Operators (e.g. --ff,  ==,  !!,  etc.)  must  be
                     unquoted.
                +o    The  second  operand of !!== and == expressions
                     are patterns (e.g.,  the  comparison  in  [[[[
                     ffoooobbaarr == ff**rr ]]]] succeeds)
                +o    There are two additional binary operators: <<
                     and >>  which  return  true  if  their  first
                     string  operand  is  less  than,  or greater
                     than, their second string  operand,  respec-
                     tively.
                +o    The  single  argument  form  of  tteesstt, which
                     tests if the argument has  non-zero  length,
                     is not valid because explicit operators must
                     be always be used.

   QQuuoottiinngg
       Quoting is used to prevent the shell from treating charac-
       ters or words specially.  There are three methods of quot-
       ing: First, \\ quotes the following character, unless it is
       at  the  end  of  a line, in which case both the \\ and the
       newline are stripped.  Second, a single quote  ('')  quotes
       everything  up  to  the  next  single quote (this may span
       lines).  Third, a double quote ("") quotes all  characters,



                        November 28, 1994                       6





KSH(1)                    User commands                    KSH(1)


       except  $$,  `` and \\, up to the next unquoted double quote.
       $$ and `` inside double  quotes  have  their  usual  meaning
       (i.e.,  parameter,  command  or  arithmetic  substitution)
       except no field splitting is carried out on the results of
       double-quoted  substitutions.   If  a  \\  inside a double-
       quoted string is followed by \\, $$, `` or "", it is  replaced
       by  the  second character; if it is followed by a newline,
       both the \\ and the newline are stripped;  otherwise,  both
       the \\ and the character following are unchanged.

       Note:  see  POSIX  Mode below for a special rule regarding
       sequences of the form ""...``...\\""...``.."".

   AAlliiaasseess
       There are two types of aliases: normal command aliases and
       tracked  aliases.   Command aliases are normally used as a
       short hand for a long or often used  command.   The  shell
       expands  command aliases (i.e., substitutes the alias name
       for its value) when it reads the first word of a  command.
       An  expanded  alias  is  re-processed  to  check  for more
       aliases.  If a command alias ends in a space or  tab,  the
       following  word  is also checked for alias expansion.  The
       alias expansion process stops when a word that is  not  an
       alias  is  found,  when  a quoted word is found or when an
       alias word that is currently being expanded is found.

       The following command aliases are defined automatically by
       the shell:
              aauuttoollooaadd==''ttyyppeesseett --uuff''
              ffuunnccttiioonnss==''ttyyppeesseett --ff''
              hhaasshh==''aalliiaass --tt ----''
              hhiissttoorryy==''ffcc --ll''
              iinntteeggeerr==''ttyyppeesseett --ii''
              llooccaall==''ttyyppeesseett''
              llooggiinn==''eexxeecc llooggiinn''
              nneewwggrrpp==''eexxeecc nneewwggrrpp''
              nnoohhuupp==''nnoohhuupp ''
              ppwwdd==''pprriinntt --rr ---- $$PPWWDD''
              rr==''ffcc --ee --''
              ssttoopp==''kkiillll --SSTTOOPP $$$$''
              ssuussppeenndd==''kkiillll --SSTTOOPP $$$$''
              ttyyppee==''wwhheennccee --vv''

       Tracked aliases allow the shell to remember where it found
       a particular command.  The first time  the  shell  does  a
       path  search  for  a  command  that is marked as a tracked
       alias, it saves the full path of the  command.   The  next
       time  the  command is executed, the shell checks the saved
       path to see that it is still  valid,  and  if  so,  avoids
       repeating  the path search.  Tracked aliases can be listed
       and created using aalliiaass --tt.  Note that changing  the  PPAATTHH
       parameter  clears the saved paths for all tracked aliases.
       If the ttrraacckkaallll option is set (i.e., sseett  --oo  ttrraacckkaallll  or
       sseett  --hh),  the  shell tracks all commands.  This option is



                        November 28, 1994                       7





KSH(1)                    User commands                    KSH(1)


       set automatically for non-interactive shells.  For  inter-
       active  shells,  only the following commands are automati-
       cally tracked: ccaatt, cccc, cchhmmoodd, ccpp, ddaattee, eedd, eemmaaccss,  ggrreepp,
       llss, mmaaiill, mmaakkee, mmvv, pprr, rrmm, sseedd, sshh, vvii and wwhhoo.

   SSuubbssttiittuuttiioonn
       The  first  step  the  shell  takes in executing a simple-
       command is to perform substitutions on the  words  of  the
       command.   There  are three kinds of substitution: parame-
       ter, command  and  arithmetic.   Parameter  substitutions,
       which  are  described  in detail in the next section, take
       the form $$nnaammee or $${{...}}; command substitutions  take  the
       form $$((_c_o_m_m_a_n_d)) or ``_c_o_m_m_a_n_d``; and arithmetic substitutions
       take the form $$((((_e_x_p_r_e_s_s_i_o_n)))).

       If a substitution appears outside of  double  quotes,  the
       results  of the substitution are generally subject to word
       or field splitting according to the current value  of  the
       IIFFSS  parameter.   The  IIFFSS  parameter  specifies a list of
       characters which are used to break a string up  into  sev-
       eral  words;  any  characters  from the set space, tab and
       newline that appear in the IFS characters are  called  _I_F_S
       _w_h_i_t_e  _s_p_a_c_e.   Sequences  of  one or more IFS white space
       characters, in combination with zero or one non-IFS  white
       space  characters  delimit  a  field.   As a special case,
       leading and trailing IFS white space is stripped (i.e., no
       leading or trailing empty field is created by it); leading
       or trailing non-IFS  white  space  does  create  an  empty
       field.  Example: if IIFFSS is set to `<space>:', the sequence
       of  characters  `<space>A<space>:<space><space>B::D'  con-
       tains four fields: `A', `B', `' and `D'.  Note that if the
       IIFFSS parameter is set to the null string, no  field  split-
       ting is done; if the parameter is unset, the default value
       of space, tab and newline is used.

       The results of substitution are, unless  otherwise  speci-
       fied, also subject to brace expansion and file name expan-
       sion (see the relevant sections below).

       A command substitution is replaced by the output generated
       by the specified command, which is run in a subshell.  For
       $$((_c_o_m_m_a_n_d)) substitutions, normal quoting  rules  are  used
       when _c_o_m_m_a_n_d is parsed, however, for the ``_c_o_m_m_a_n_d`` form, a
       \\ followed by any of $$, `` or \\ is stripped (a  \\  followed
       by  any  other character is unchanged).  As a special case
       in command substitutions, a command of the form << _f_i_l_e  is
       interpreted  to  mean substitute the contents of _f_i_l_e ($(<
       foo) has the same effect as $(cat foo), but it is  carried
       out more efficiently because no process is started).
       NOTE: $$((_c_o_m_m_a_n_d)) expressions are currently parsed by find-
       ing the matching parenthesis, regardless of quoting.  This
       will hopefully be fixed soon.

       Arithmetic  substitutions are replaced by the value of the



                        November 28, 1994                       8





KSH(1)                    User commands                    KSH(1)


       specified  expression.   For  example,  the  command  eecchhoo
       $$((((22++33**44))))  prints  14.   See Arithmetic Expressions for a
       description of an _e_x_p_r_e_s_s_i_o_n.

   PPaarraammeetteerrss
       Parameters are shell variables; they can be assigned  val-
       ues  and  their  values  can be accessed using a parameter
       substitution.  A parameter name is either one of the  spe-
       cial  single  punctuation  or  digit  character parameters
       described below, or a letter followed by zero or more let-
       ters  or  digits (`_' counts as a letter).  Parameter sub-
       stitutions take the form $$_n_a_m_e or $${{_n_a_m_e}}, where _n_a_m_e is a
       parameter name.  If substitution is performed on a parame-
       ter that is not set, a null string is  substituted  unless
       the  nnoouunnsseett  option (sseett --oo nnoouunnsseett or sseett --uu) is set, in
       which case an error occurs.

       Parameters can be assigned values in  a  number  of  ways.
       First,  the  shell implicitly sets some parameters like ##,
       PPWWDD, etc.; this is the only way the special single charac-
       ter  parameters  are set.  Second, parameters are imported
       from the shell's environment at startup.   Third,  parame-
       ters can be assigned values on the command line, for exam-
       ple, `FFOOOO==bbaarr' sets the parameter  FOO  to  bar;  multiple
       parameter  assignments  can  be  given on a single command
       line and they can be  followed  by  a  simple-command,  in
       which  case  the  assignments  are  in effect only for the
       duration  of  the  command  (such  assignments  are   also
       exported,  see below for implications of this).  Note that
       both the parameter name and the == must be unquoted for the
       shell to recognize a parameter assignment.  The fourth way
       of setting a parameter is with the  eexxppoorrtt,  rreeaaddoonnllyy  and
       ttyyppeesseett  commands;  see  their descriptions in the Command
       Execution section.  Fifth, ffoorr and sseelleecctt loops set param-
       eters  as  well  as the ggeettooppttss, rreeaadd and sseett --AA commands.
       Lastly, parameters can be assigned values using assignment
       operators  inside  arithmetic  expressions (see Arithmetic
       Expressions below) or using the $${{_n_a_m_e[::]==_v_a_l_u_e}}  form  of
       parameter substitution (see below).

       Parameters with the export attribute (set using the eexxppoorrtt
       or ttyyppeesseett --xx commands, or by parameter  assignments  fol-
       lowed  by simple commands) are put in the environment (see
       _e_n_v_i_r_o_n(5)) of commands run by  the  shell  as  _n_a_m_e==_v_a_l_u_e
       pairs.   The order in which parameters appear in the envi-
       ronment of a  command  is  unspecified.   When  the  shell
       starts  up,  it  extracts parameters and their values from
       its  environment  and  automatically   sets   the   export
       attribute for those parameters.

       Modifiers  can be applied to the $${{_n_a_m_e}} form of parameter
       substitution:





                        November 28, 1994                       9





KSH(1)                    User commands                    KSH(1)


       $${{_n_a_m_e::--_w_o_r_d}}
              if _n_a_m_e is set and not  null,  it  is  substituted,
              otherwise _w_o_r_d is substituted.

       $${{_n_a_m_e::++_w_o_r_d}}
              if  _n_a_m_e  is set and not null, _w_o_r_d is substituted,
              otherwise nothing is substituted.

       $${{_n_a_m_e::==_w_o_r_d}}
              if _n_a_m_e is set and not  null,  it  is  substituted,
              otherwise  it  is  assigned  _w_o_r_d and the resulting
              value of _n_a_m_e is substituted.

       $${{_n_a_m_e::??_w_o_r_d}}
              if _n_a_m_e is set and not  null,  it  is  substituted,
              otherwise  _w_o_r_d  is printed on standard error (pre-
              ceded by _n_a_m_e:) and an error occurs (normally caus-
              ing  termination  of  a  shell  script, function or
              .-script).  If word is omitted the string  `parame-
              ter null or not set' is used instead.

       In  the  above  modifiers,  the :: can be omitted, in which
       case the conditions only depend  on  _n_a_m_e  being  set  (as
       opposed  to  set  and not null).  In addition to brace and
       file name expansion, tilde expansion is also performed  on
       _w_o_r_d.   Also,  _w_o_r_d  is evaluated only if the condition is
       true (e.g., eecchhoo $${{vv--$$((sslleeeepp 1100;; eecchhoo  hhii))}}  will  immedi-
       ately  print  the  value  of vv if it is set, otherwise, it
       will sleep for 10 seconds and print hi).

       The following forms of parameter substitution can also  be
       used:

       $${{##_n_a_m_e}}
              The number of positional parameters if _n_a_m_e is ** or
              @@, the number of elements in  the  named  array  if
              _n_a_m_e  is  an  array,  or finally, the length of the
              string value of parameter _n_a_m_e.

       $${{_n_a_m_e##_p_a_t_t_e_r_n}}, $${{_n_a_m_e####_p_a_t_t_e_r_n}}
              If _p_a_t_t_e_r_n matches the beginning of  the  value  of
              parameter  _n_a_m_e,  the  matched text is deleted from
              the result of substitution.  A single ## results  in
              the  shortest match, two ##'s results in the longest
              match.

       $${{_n_a_m_e%%_p_a_t_t_e_r_n}}, $${{_n_a_m_e%%%%_p_a_t_t_e_r_n}}
              Like $${{..##..}} substitution, but it deletes from the
              end of the value.

       The following special parameters are implicitly set by the
       shell and cannot be set directly using assignments:

       !!      Process id of the last background process  started.



                        November 28, 1994                      10





KSH(1)                    User commands                    KSH(1)


              If  no  background processes have been started, the
              parameter is not set.

       ##      The number of positional parameters (i.e., $$11,  $$22,
              etc.).

       $$      The  process  ID  of  the  shell, or the PID of the
              original shell if it is a subshell.

       --      The concatenation  of  the  current  single  letter
              options   (see   sseett  command  below  for  list  of
              options).

       ??      The exit status of the last  non-asynchronous  com-
              mand executed.  If the last command was killed by a
              signal, $$?? is set to 128 plus the signal number.

       00      The  name  the  shell  was  invoked   with   (i.e.,
              aarrggvv[[00]]),  or  the  ccoommmmaanndd--nnaammee  if it was invoked
              with the --cc option and the  ccoommmmaanndd--nnaammee  was  sup-
              plied,  or  the  _f_i_l_e argument, if it was supplied.
              In functions and ..-scripts, $$00 is the name  of  the
              function or script, respectively.

       11 ... 99
              The first nine positional parameters that were sup-
              plied to the shell, function or ..-script.   Further
              positional  parameters may be accessed using $${{_n_u_m_-
              _b_e_r}}.

       **      All positional parameters (except parameter 0) con-
              catenated to one string.

       @@      Same as $$**, unless it is used inside double quotes,
              in which case a separate word is generated for each
              positional  parameter  - if there are no positional
              parameters, no word is generated ("$@" can be  used
              to  access arguments, verbatim, without losing null
              arguments or splitting arguments with spaces).

       The following parameters are set and/or used by the shell:

       __ _(_u_n_d_e_r_s_c_o_r_e_)
              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 is placed in the command's envi-
              ronment.   When  MMAAIILLPPAATTHH  messages  are evaluated,
              this parameter contains the name of the  file  that
              changed (see MMAAIILLPPAATTHH parameter below).

       CCDDPPAATTHH Search path for the ccdd built-in command.  Works the
              same way as PPAATTHH for those directories  not  begin-
              ning with // in ccdd commands.



                        November 28, 1994                      11





KSH(1)                    User commands                    KSH(1)


       CCOOLLUUMMNNSS
              Set  to  the  number  of columns on the terminal or
              window.   Currently  set  to  the  ccoollss  value   as
              reported  by  _s_t_t_y(1)  if  that  value is non-zero.
              This parameter is  used  by  the  interactive  line
              editing  modes,  and  by sseelleecctt, sseett --oo and kkiillll --ll
              commands to format information in columns.

       EEDDIITTOORR If the VVIISSUUAALL parameter is not set, this  parameter
              controls the command line editing mode for interac-
              tive shells.  See VVIISSUUAALL parameter  below  for  how
              this works.

       EENNVV    If this parameter is found to be set after any pro-
              file files are executed, the expanded value is used
              as  a  shell  start-up file.  It typically contains
              function and alias definitions.

       EERRRRNNOO  Integer value of the shell's errno variable - indi-
              cates the reason the last system call failed.

              Not implemented yet.

       EEXXEECCSSHHEELLLL
              If  set,  this  parameter is assumed to contain the
              shell that is to be used to execute  commands  that
              _e_x_e_c_v_e(2)  fails  to execute and which do not start
              with a `##!! _s_h_e_l_l' sequence.

       FFCCEEDDIITT The editor used by the ffcc command.

       FFPPAATTHH  Like PPAATTHH, but used when an undefined  function  is
              executed  to locate the file defining the function.
              It is also searched when a command can't  be  found
              using  PPAATTHH.  See Functions below for more informa-
              tion.

       HHIISSTTFFIILLEE
              The name of the file used to store  history.   When
              assigned  to,  history is loaded from the specified
              file.  Also, several invocations of the shell  run-
              ning  on  the  same  machine  will share history if
              their HHIISSTTFFIILLEE parameters all  point  at  the  same
              file.

       HHIISSTTSSIIZZEE
              The number of commands normally stored for history,
              default 128.

       HHOOMMEE   The default directory for the ccdd  command  and  the
              value  substituted  for an unqualified ~~ (see Tilde
              Expansion below).

       IIFFSS    Internal field separator, used during  substitution



                        November 28, 1994                      12





KSH(1)                    User commands                    KSH(1)


              and  by the rreeaadd command, to split values into dis-
              tinct arguments; normally set  to  space,  tab  and
              newline.  See Substitution above for details.
              NNoottee:: this parameter is not imported from the envi-
              ronment when the shell is started.

       KKSSHH__VVEERRSSIIOONN
              The version of shell and the date the  version  was
              created (readonly).

       LLIINNEENNOO The  line  number  of  the function or shell script
              that is currently being executed.

              Not implemented yet.

       LLIINNEESS  Set to the number of lines on the terminal or  win-
              dow.

              Not implemented yet.

       MMAAIILL   If set, the user will be informed of the arrival of
              mail in the named file.  This parameter is  ignored
              if the MMAAIILLPPAATTHH parameter is set.

       MMAAIILLCCHHEECCKK
              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 (5 minutes).

       MMAAIILLPPAATTHH
              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, during substitution,
              the  parameter  $$__  contains  the name of the file.
              The default message is yyoouu hhaavvee mmaaiill iinn $$__.

       OOLLDDPPWWDD The previous working directory.  Unset  if  ccdd  has
              not  successfully  changed  directories  since  the
              shell started (readonly).

       OOPPTTAARRGG When using ggeettooppttss, it contains the argument for  a
              parsed option, if it requires one.

       OOPPTTIINNDD The index of the last argument processed when using
              ggeettooppttss.  Assigning  1  to  this  parameter  causes
              ggeettooppttss to process arguments from the beginning the
              next time it is invoked.

       PPAATTHH   A colon separated  list  of  directories  that  are
              searched  when  looking for commands and ..'d files.
              An  empty  string  resulting  from  a  leading   or



                        November 28, 1994                      13





KSH(1)                    User commands                    KSH(1)


              trailing  colon,  or two adjacent colons is treated
              as a `.', the current directory.

       PPOOSSIIXXLLYY__CCOORRRREECCTT
              If set, this parameter causes the ppoossiixx  option  to
              be enabled.  See POSIX Mode below.

       PPPPIIDD   The process ID of the shell's parent (readonly).

       PPSS11    PPSS11  is  the primary prompt for interactive shells.
              Parameter, command and arithmetic substitutions are
              performed,  and !! is replaced with the current com-
              mand number (see ffcc  command  below).   Default  is
              `$$ '.

       PPSS22    Secondary prompt string, by default `>> ', used when
              more input is needed to complete a command.

       PPSS33    Prompt used by sseelleecctt statement when reading a menu
              selection.  Default is `##?? '.

       PPSS44    Used  to  prefix  commands  that are printed during
              execution  tracing  (see  sseett  --xx  command  below).
              Parameter, command and arithmetic substitutions are
              performed before it is printed.

       PPWWDD    The current working directory (readonly).

       RRAANNDDOOMM A simple random number generator.  Every time  RRAANN--
              DDOOMM  is  referenced, it is assigned the next number
              in a random number series.  The point in the series
              can  be  set  by  assigning a number to RRAANNDDOOMM (see
              _r_a_n_d(3)).

       RREEPPLLYY  Default parameter for the rreeaadd command if no  names
              are  given.  Also used in sseelleecctt loops to store the
              value that is read from standard input.

       SSEECCOONNDDSS
              The number of seconds since the shell  started  or,
              if  the  parameter  has  been  assigned  an integer
              value, the number of seconds since  the  assignment
              plus the value that was assigned.

       TTMMOOUUTT  If  set  to  a  positive  integer in an interactive
              shell, it specifies the maximum number  of  seconds
              the  shell  will  wait for input after printing the
              primary prompt (PPSS11).  If the time is exceeded, the
              shell exits.

       TTMMPPDDIIRR The directory shell temporary files are created in.
              If this parameter is not set, or does  not  contain
              the  absolute  path of a writable directory, tempo-
              rary files are created in //ttmmpp.



                        November 28, 1994                      14





KSH(1)                    User commands                    KSH(1)


       VVIISSUUAALL If set, this parameter controls  the  command  line
              editing  mode  for interactive shells.  If the last
              component of the path specified in  this  parameter
              contains  the  string  vvii,  eemmaaccss or ggmmaaccss, the vi,
              emacs or gmacs  (Gosling  emacs)  editing  mode  is
              enabled, respectively.

   TTiillddee EExxppaannssiioonn
       Tilde  expansion, which is done in parallel with parameter
       substitution, is done on words starting with  an  unquoted
       ~~.  The characters following the tilde, up to the first //,
       if any, are assumed to be a login name.  If the login name
       is  empty,  ++  or --, the value of the HHOOMMEE, PPWWDD, or OOLLDDPPWWDD
       parameter is substituted,  respectively.   Otherwise,  the
       password  file  is  searched  for  the login name, and the
       tilde expression  is  substituted  with  the  user's  home
       directory.  If the login name is not found in the password
       file or if any quoting or parameter substitution occurs in
       the login name, no substitution is performed.

       In parameter assignments (those preceding a simple-command
       or those occurring in the arguments of aalliiaass, eexxppoorrtt rreeaadd--
       oonnllyy,  and  ttyyppeesseett),  tilde  expansion  is done after any
       unquoted colon (::), and login names are also delimited  by
       colons.

       The  home directory of previously expanded login names are
       cached and re-used.  The aalliiaass --dd command may be  used  to
       list,  change  and  add  to  this  cache  (e.g., `alias -d
       fac=/usr/local/facilities; cd ~fac/bin').

   BBrraaccee EExxppaannssiioonn ((aalltteerrnnaattiioonn))
       Brace expressions, which take the form
                      _p_r_e_f_i_x {{_s_t_r1,,...,,_s_t_rN}}_s_u_f_f_i_x
       are expanded to N words, each of which is  the  concatena-
       tion  of  _p_r_e_f_i_x,  _s_t_ri and _s_u_f_f_i_x (e.g., `a{c,b{X,Y},d}e'
       expands to four word: ace, abXe, abYe, and ade).  As noted
       in  the  example,  brace expressions can be nested and the
       resulting words are not sorted.   Brace  expressions  must
       contain  an  unquoted  comma  (,,)  for  expansion to occur
       (i.e., {{}} and {{ffoooo}} are not expanded).  Brace expansion is
       carried  out  after parameter substitution and before file
       name generation.

   FFiillee NNaammee PPaatttteerrnnss
       A file name pattern is  a  word  containing  one  or  more
       unquoted  ?? or ** characters or [[..]] sequences.  Once brace
       expansion has been performed, the shell replaces file name
       patterns with the sorted names of all the files that match
       the  pattern  (if  no  files  match,  the  word  is   left
       unchanged).  The pattern elements have the following mean-
       ing:

       ??      matches any single character.



                        November 28, 1994                      15





KSH(1)                    User commands                    KSH(1)


       **      matches any sequence of characters.

       [[..]]   matches any of the characters inside the  brackets.
              Ranges of characters can be specified by separating
              two characters by a --,  e.g.,  [[aa00--99]]  matches  the
              letter  aa  or  any  digit.   In  order to represent
              itself, a -- must either be quoted or the  first  or
              last character in the character list.  Similarly, a
              ]] must be quoted or the first character in the list
              if it is represent itself instead of the end of the
              list.  Also, a !!  appearing at  the  start  of  the
              list  has special meaning (see below), so to repre-
              sent itself it must be quoted or  appear  later  in
              the list.

       [[!!..]]  like  [[..]],  except  it  matches  any character not
              inside the brackets.

       Note that pdksh currently never matches .. and ...., but  the
       original  ksh,  Bourne sh and bash do, so this may have to
       change (too bad).

       Note that none of the above pattern elements match  either
       a  period (..)  at the start of a file name or a slash (//),
       even if they are explicitly used in a [[..]] sequence; also,
       the names .. and ....  are never matched, even by the pattern
       ..**.

       If the mmaarrkkddiirrss option is set, any directories that result
       from file name generation are marked with a trailing //.

       The  ??((_p_a_t_t_e_r_n_-_l_i_s_t)),  **((_p_-_l)),  ++((_p_-_l)),  @@((_p_-_l)) and !!((_p_-_l))
       elements found in the original  Korn  shell  are  not  yet
       implemented;  the  same  is  true  for the POSIX character
       classes (i.e., [[::_c_l_a_s_s_-_n_a_m_e::]] inside a [[..]] expression).

   IInnppuutt//OOuuttppuutt RReeddiirreeccttiioonn
       When a command is executed, its standard  input,  standard
       output  and  standard  error (file descriptors 0, 1 and 2,
       respectively)  are  normally  inherited  from  the  shell.
       Three  exceptions  to  this are commands in pipelines, for
       which standard input and/or standard output are those  set
       up by the pipeline, asynchronous commands created when job
       control is disabled, for which standard input is initially
       set  to  be  from //ddeevv//nnuullll, and commands for which any of
       the following redirections have been specified:

       >> _f_i_l_e standard output is redirected  to  _f_i_l_e.   If  _f_i_l_e
              does not exist, it is created; if it does exist and
              the nnoocclloobbbbeerr option is set, an error occurs,  oth-
              erwise the file is truncated.  Note that this means
              the command _c_m_d _< _f_o_o _> _f_o_o will open _f_o_o for read-
              ing and then truncate it when it opens it for writ-
              ing, before _c_m_d gets a chance to actually read _f_o_o.



                        November 28, 1994                      16





KSH(1)                    User commands                    KSH(1)


       >>|| _f_i_l_e
              same  as  >>,  except the file is truncated, even if
              the nnoocclloobbbbeerr option is set.

       >>>> _f_i_l_e
              same as >>, except the  file  an  existing  file  is
              appended  to instead of being truncated.  Also, the
              file is opened in append mode, so writes always  go
              to the end of the file (see _o_p_e_n(2)).

       << _f_i_l_e standard  input  is  redirected from _f_i_l_e, which is
              opened for reading.

       <<>> _f_i_l_e
              same as <<, except the file is  opened  for  reading
              and writing.

       <<<< _m_a_r_k_e_r
              after reading the command line containing this kind
              of redirection (called a here document), the  shell
              copies  lines from the command source into a tempo-
              rary file until a line  matching  _m_a_r_k_e_r  is  read.
              When  the  command  is  executed, standard input is
              redirected from the temporary file.  If _m_a_r_k_e_r con-
              tains  no  quoted  characters,  the contents of the
              temporary file are processed as if enclosed in dou-
              ble  quotes  each  time the command is executed, so
              parameter, command and arithmetic substitutions are
              performed,  along with backslash (\\) escapes for $$,
              ``, \\ and \\nneewwlliinnee.  If multiple here documents  are
              used  on  the  same command line, they are saved in
              order.

       <<<<-- _m_a_r_k_e_r
              same as <<<<, except leading tabs are  stripped  from
              lines in the here document.

       <<&& _f_d  standard  input  is duplicated from file descriptor
              _f_d.  _f_d can be a single digit, indicating the  num-
              ber  of  an existing file descriptor, the letter pp,
              indicating the file descriptor associated with  the
              output  of the current co-process, or the character
              --, indicating standard input is to be closed.

       >>&& _f_d  same as <<&&, except the operation is done  on  stan-
              dard output.

       In any of the above redirections, the file descriptor that
       is redirected (i.e., standard input  or  standard  output)
       can  be explicitly given by preceding the redirection with
       a single digit.  Parameter, command and arithmetic substi-
       tutions,  tilde substitutions and file name generation are
       all performed on the _f_i_l_e,  _m_a_r_k_e_r  and  _f_d  arguments  of
       redirections.   Note however, that the results of any file



                        November 28, 1994                      17





KSH(1)                    User commands                    KSH(1)


       name generation are only used if a single file is matched;
       if multiple files match, the word with the unexpanded file
       name  generation  characters  is  used.   Note   that   in
       restricted  shells,  redirections  which  can create files
       cannot be used.

       For simple-commands, redirections may appear  anywhere  in
       the  command, for compound-commands (iiff statements, etc.),
       redirections must appear at  the  end.   Redirections  are
       processed  after  pipelines  are  created and in the order
       they are given, so
                 ccaatt //ffoooo//bbaarr 22>>&&11 >> //ddeevv//nnuullll || ccaatt --nn
       will print an error with a line number prepended to it.

   AArriitthhmmeettiicc EExxpprreessssiioonnss
       Integer arithmetic expressions can be used  with  the  lleett
       command, inside $$((..)) expressions, inside array references
       (e.g., _n_a_m_e[[_e_x_p_r]]), as numeric arguments to the tteesstt  com-
       mand,  and  as  the  value  of an assignment to an integer
       parameter.

       Expression may  contain  alpha-numeric  parameter  identi-
       fiers,  array references, and integer constants and may be
       combined with the following operators (listed and  grouped
       in increasing order of precedence).

       Unary operators:
              ++ -- !! ~~

       Binary operators:
              == **== //== %%== ++== --== <<<<== >>>>== &&== ^^== ||==, ||||, &&&&, ||, ^^, &&,
              ==== !!==, << <<== >>== >>, <<<< >>>>, ++ --, ** // %%

       Ternary operators:
              ?? :: (precedence is between that of  binary  assign-
              ment and |||| operators)

       Grouping operators:
              (( ))

       Integer  constants  may  be specified with arbitrary bases
       using the notation _b_a_s_e##_n_u_m_b_e_r, where _b_a_s_e  is  a  decimal
       integer specifying the base, and _n_u_m_b_e_r is a number in the
       specified base.

   CCoo--PPrroocceesssseess
       A Co-process, which is a  pipeline  created  with  the  ||&&
       operator,  is  an  asynchronous process that the shell can
       both write to (using pprriinntt --pp) and read from  (using  rreeaadd
       --pp).  Only one co-process may be active at any given time,
       unless the input of an existing co-process has been dupli-
       cated  using  a  >>&&pp redirection.  In this case, the shell
       closes its copy of the co-process input (note that  a  <<&&pp
       redirection  does not cause the shell to close its copy of



                        November 28, 1994                      18





KSH(1)                    User commands                    KSH(1)


       the co-process output).  Once rreeaadd --pp has read the end-of-
       file, the co-process input is closed, and further attempts
       to read will produce diagnostics.  Similarly,  once  pprriinntt
       --pp fails due to an EPIPE, the co-process output is closed.
       Note also, that pprriinntt --pp will ignore SIGPIPE signals  dur-
       ing  writes if the signal is not being trapped or ignored;
       the same is not true if  the  co-process  input  has  been
       duplicated  to  another  file  descriptor and pprriinntt --uu_n is
       used.

       If another co-process is started before doing  a  read  or
       <<&&pp  redirection from existing co-processes, the output of
       the co-processes will be shared (e.g.,  eecchhoo  hhii  ||&&  eecchhoo
       tthheerree||&&  ccaatt  <<&&pp will print both "hi" and "there").  This
       is slightly different from  the  original  Korn  shell  in
       which  output is shared as long as the existing co-process
       job has not exited.  As a side affect, end-of-file can not
       be  read reliably in the original Korn shell (e.g., if the
       co-process closes its output but does not exit, the end of
       file will not be read).

   FFuunnccttiioonnss
       Functions  are  defined  using  either Korn shell ffuunnccttiioonn
       _n_a_m_e syntax or the Bourne/POSIX shell _n_a_m_e(())  syntax.   At
       the  moment,  there  is no difference between the two, but
       see below.  Functions are like ..-scripts in that they  are
       executed  in  the  current  environment,  however,  unlike
       ..-scripts, shell arguments (i.e.,  positional  parameters,
       $$11,  etc.)  are never visible inside them.  When the shell
       is determining the location of as command,  functions  are
       searched after special built-in commands, and before regu-
       lar and non-regular built-ins,  and  before  the  PPAATTHH  is
       searched.

       An  existing  function may be deleted using uunnsseett --ff _f_u_n_c_-
       _t_i_o_n_-_n_a_m_e.  A list of  functions  can  be  obtained  using
       ttyyppeesseett  ++ff  and  the  function  definitions can be listed
       using ttyyppeesseett --ff.  aauuttoollooaadd (which is an alias for ttyyppeesseett
       --ffuu)  may  be  used to create undefined functions; when an
       undefined function is executed,  the  shell  searches  the
       path  specified in the FFPPAATTHH parameter for a file with the
       same name as the function, which, if  found  is  read  and
       executed.  If after executing the file, the named function
       is found to be defined, the function is  executed,  other-
       wise,  the  normal  command search is continued (i.e., the
       shell searches the builtin-command table and PPAATTHH).   Note
       that  if  a command is not found using PPAATTHH, an attempt is
       made to autoload a function using FFPPAATTHH (this is an undoc-
       umented feature of the original Korn shell).

       Functions can have two attributes, trace and export, which
       can be set with ttyyppeesseett --fftt and ttyyppeesseett --ffxx, respectively.
       When  a  traced  function  is executed, the shell's xxttrraaccee
       option is turned on for the functions duration,  otherwise



                        November 28, 1994                      19





KSH(1)                    User commands                    KSH(1)


       the  xxttrraaccee option is turned off.  The export attribute of
       functions is currently not used.   In  the  original  Korn
       shell,  exported  functions  are  visible to shell scripts
       that are executed.

       Since functions are executed in the current shell environ-
       ment, parameter assignments made inside functions are vis-
       ible after the function completes.  If  this  is  not  the
       desired  effect,  the ttyyppeesseett command can be used inside a
       function to create a local parameter.  Note  that  special
       parameters (e.g., $$$$, $$!!) can't be scoped in this way.

       The  exit status of a function is that of the last command
       executed in the function.  A function can be made to  fin-
       ish immediately using the rreettuurrnn command; this may also be
       used to explicitly specify the exit status.

       In future, functions defined  with  the  ffuunnccttiioonn  keyword
       will  be  treated  differently than functions defined with
       the (()) notation:
         +o    A separate trap/signal environment is  used  during
              the  execution  of functions.  This means traps set
              inside a function do not affect the  shell's  traps
              and  signals that are not ignored in the shell (but
              may be trapped) have  their  default  effect  in  a
              function.
         +o    The  EXIT  trap,  if set in a function, is executed
              after the function returns.
         +o    the $$00 parameter will be set to  the  name  of  the
              function  (this  is  currently  the  case  for both
              styles of function).

   PPOOSSIIXX MMooddee
       pdksh is intended to be POSIX compliant, however, in  some
       cases,  POSIX behaviour is contrary either to the original
       Korn shell behaviour or  to  user  convenience.   How  the
       shell behaves in these cases is determined by the state of
       the posix option (sseett --oo ppoossiixx) -- if it is on, the  POSIX
       behaviour  is  followed,  otherwise  it  isn't.  The ppoossiixx
       option is set automatically when the shell  starts  up  if
       the  environment  contains  the PPOOSSIIXXLLYY__CCOORRRREECCTT parameter.
       (pdksh can also be compiled so that it is in POSIX mode by
       default, however this is usually not desirable).

       The following is a list of things that are affected by the
       state of the ppoossiixx option:
         +o    \\"" inside double quoted ``..`` command substitutions:
              in  posix mode, the \\"" is interpreted when the com-
              mand is interpreted; in non-posix mode,  the  back-
              slash  is  stripped before the command substitution
              is interpreted.  For example, eecchhoo ""``eecchhoo  \\""hhii\\""``""
              produces  `"hi"'  in  posix mode, `hi' in non-posix
              mode.  To avoid problems, use the $$((......)   form  of
              command substitution.



                        November 28, 1994                      20





KSH(1)                    User commands                    KSH(1)


         +o    kkiillll  --ll  output:  in  posix mode, signal names are
              listed one a single line; in non-posix mode, signal
              numbers,  names  and  descriptions  are  printed in
              columns.  In future, a new option (--vv perhaps) will
              be added to distinguish the two behaviours.
         +o    ffgg exit status: in posix mode, the exit status is 0
              if no errors occur; in  non-posix  mode,  the  exit
              status is that of the last foregrounded job.
         +o    ggeettooppttss:  in  posix mode, options must start with a
              --; in non-posix mode, options can start with either
              -- or ++.
         +o    brace  expansion  (also  known  as alternation): in
              posix mode, brace expansion is  disabled;  in  non-
              posix mode, brace expansion enabled.  Note that sseett
              --oo ppoossiixx (or setting the PPOOSSIIXXLLYY__CCOORRRREECCTT parameter)
              automatically  turns  the  bbrraacceeeexxppaanndd  option off,
              however it can be explicitly turned on later.
         +o    sseett --: in posix mode, this does not clear the  vveerr--
              bboossee or xxttrraaccee options; in non-posix mode, it does.
         +o    sseett exit status: in posix mode, the exit status  of
              set is 0 if there are no errors; in non-posix mode,
              the exit status is that of  any  command  substitu-
              tions performed in generating the set command.  For
              example, `sseett ---- ``ffaallssee``;;  eecchhoo  $$??'  prints  0  in
              posix mode, 1 in non-posix mode.  This construct is
              used  in  most  shell  scripts  that  use  the  old
              _g_e_t_o_p_t(1) command.
         +o    argument  expansion of aalliiaass, eexxppoorrtt, rreeaaddoonnllyy, and
              ttyyppeesseett commands: in posix  mode,  normal  argument
              expansion done; in non-posix mode, field splitting,
              file globing, (normal) tilde expansion  are  turned
              off, and assignment tilde expansion is turned on.
         +o    signal specification: in posix mode, signals can be
              specified as digits only if  signal  numbers  match
              POSIX  values  (i.e., HUP=1, INT=2, QUIT=3, ABRT=6,
              KILL=9, ALRM=14, and TERM=15); in  non-posix  mode,
              signals can be always digits.
         +o    alias  expansion: in posix mode, alias expansion is
              only carried out when  reading  command  words;  in
              non-posix  mode,  alias expansion is carried out on
              any word following an alias that ended in a  space.
              For example, the following for loop
              aalliiaass aa==''ffoorr '' ii==''jj''
              aa ii iinn 11 22;; ddoo eecchhoo ii==$$ii jj==$$jj;; ddoonnee
       uses parameter ii in posix mode, jj in non-posix mode.

   CCoommmmaanndd EExxeeccuuttiioonn
       After evaluation of keyword assignments and arguments, the
       type of command is determined.  A command  may  execute  a
       special  shell built-in, a shell function, a regular shell
       built-in, or an executable file.

       Any keyword assignments are then performed (and  exported)
       for the duration of the command.



                        November 28, 1994                      21





KSH(1)                    User commands                    KSH(1)


       Even  on systems where the _e_x_e_c(2) family does not support
       ##!!  notation for scripts, ksh can be  configured  to  fake
       it.

       There are several built-in commands.

       :: [ ... ]
              The null command.  Exit status is set to zero.

       .. _f_i_l_e [_a_r_g_1 ...]
              Execute  the  commands in _f_i_l_e in the current envi-
              ronment.  The file is searched for in the  directo-
              ries  of  PPAATTHH.   If arguments are given, the posi-
              tional parameters may be used to access them  while
              _f_i_l_e is being executed.  If no arguments are given,
              the positional parameters are those of the environ-
              ment the command is used in.

       aalliiaass [ --dd | --tt [--rr] ] [--xx] [_n_a_m_e_1[==_v_a_l_u_e_1] ...]
              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 Aliases above).

              The --xx option  sets  the  export  attribute  of  an
              alias, or, if no names are given, lists the aliases
              with the export attribute (exporting an alias  cur-
              rently has no affect).

              The --tt option indicates that tracked aliases are to
              be listed/set (values specified on the command line
              are  ignored  for  tracked aliases).  The --rr option
              indicates that all tracked aliases are to be reset.

              The  --dd causes directory aliases, which are used in
              tilde expansion, to be listed  or  set  (see  Tilde
              Expansion above).

       bbgg [_j_o_b ...]
              Resume  the  specified  stopped job(s) in the back-
              ground.  If no jobs are specified, %%++  is  assumed.
              This  command  is  only  available on systems which
              support job control.  See  Job  Control  below  for
              more information.

       bbiinndd [--mm] [_k_e_y[==_e_d_i_t_i_n_g_-_c_o_m_m_a_n_d] ...]
              Set  or  view the current emacs command editing key
              bindings/macros.  See Emacs Interactive Input  Line
              Editing below for a complete description.

       bbrreeaakk [_l_e_v_e_l]
              bbrreeaakk  exits  the  _l_e_v_e_lth  inner most for, select,
              until, or while loop.  _l_e_v_e_l defaults to 1.




                        November 28, 1994                      22





KSH(1)                    User commands                    KSH(1)


       bbuuiillttiinn _c_o_m_m_a_n_d [_a_r_g_1 ...]
              Execute the built-in command _c_o_m_m_a_n_d.

       ccdd [_d_i_r]
              Set the working directory to _d_i_r.  If the parameter
              CCDDPPAATTHH  is  set,  it  lists the search path for the
              directory containing _d_i_r.  A  null  path  mans  the
              current  directory.   If  _d_i_r  is missing, the home
              directory $$HHOOMMEE is used.  If _d_i_r is --, the previous
              working  directory  is  used.  If _d_i_r is determined
              from the value of PPWWDD.  The PPWWDD and OOLLDDPPWWDD  parame-
              ters  are  updated  to  reflect the current and old
              wording directory, respectively.

              Note: the --LL and --PP options available in some  Korn
              shells  are  not implemented yet; the same goes for
              the ppwwdd command.

       ccdd _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.

       ccoommmmaanndd [--ppvvVV] _c_m_d [_a_r_g_1 ...]
              If neither the --vv nor --VV options are given, _c_m_d  is
              executed  exactly  as  if  the ccoommmmaanndd had not been
              specified, with two exceptions: first,  _c_m_d  cannot
              be  a  shell function, and second, special built-in
              commands lose their specialness (i.e.,  redirection
              and  utility errors do not cause the shell to exit,
              and command assignments are not permanent).  If the
              --pp  option  is given, a default search path is used
              instead of the current value of  PPAATTHH  (the  actual
              value  of  the default path is system dependent: on
              POSIXish systems, it is the value returned by  ggeett--
              ccoonnff CCSS__PPAATTHH).

              If  the  --vv  option  is given, instead of executing
              _c_m_d, information about what would  be  executed  is
              given  (and the same is done for _a_r_g_1 for keywords,
              special and regular  built-in  commands  and  func-
              tions, their names are simply printed, for aliases,
              a command that defines them  is  printed,  and  for
              commands found by searching the PPAATTHH parameter, the
              full path of the command is printed.  If no command
              is be found, (i.e., the path search fails), nothing
              is printed and ccoommmmaanndd exits with a  non-zero  sta-
              tus.   The  --VV option is like the --vv option, except
              it is more verbose.

       ccoonnttiinnuuee [_l_e_v_e_l_s]
              ccoonnttiinnuuee jumps to  the  beginning  of  the  _l_e_v_e_lth
              inner  most  for,  select,  until,  or  while loop.
              _l_e_v_e_l defaults to 1.



                        November 28, 1994                      23





KSH(1)                    User commands                    KSH(1)


       eecchhoo [--nneeEE] [_a_r_g ...]
              Prints its arguments (separated by spaces) followed
              by a newline, to standard out.  The newline is sup-
              pressed if any of the arguments contain  the  back-
              slash  sequence  \\cc.  See pprriinntt command below for a
              list of other backslash sequences that  are  recog-
              nized.

              The options are provided for compatibility with BSD
              shell scripts: --nn suppresses the trailing  newline,
              --ee enables backslash interpretation (a no-op, since
              this is normally done),  and  --EE  which  suppresses
              backslash interpretation.

       eevvaall _c_o_m_m_a_n_d _._._.
              The arguments are concatenated (with spaces between
              them) to form a single string which the shell  then
              parses and executes in the current environment.

       eexxeecc [_c_o_m_m_a_n_d [_a_r_g ...]]
              The  command is executed without forking, replacing
              the shell process.

              If no arguments are given, any  IO  redirection  is
              permanent  and the shell is not replaced.  Any file
              descriptors greater than  2  which  are  opened  or
              _d_u_p(2)-ed  in  this  way  are not made available to
              other executed commands (i.e.,  commands  that  are
              not built-in to the shell).

       eexxiitt [_s_t_a_t_u_s]
              The shell exits with the specified exit status.  If
              _s_t_a_t_u_s is not specified, the  exit  status  is  the
              current value of the ?? parameter.

       eexxppoorrtt [--pp] [_p_a_r_a_m_e_t_e_r[==_v_a_l_u_e]] ...
              Sets  the export attribute of the named parameters.
              Exported parameters are passed in  the  environment
              to executed commands.  If values are specified, the
              named parameters also assigned.

              If no parameters are specified, the  names  of  all
              parameters  with  the  export attribute are printed
              one per line, unless the  --pp  option  is  used,  in
              which  case  eexxppoorrtt  commands defining all exported
              parameters, including their values, are printed.

       ffaallssee  A command that exits with a non-zero status.

       ffcc [--ee _e_d_i_t_o_r | --ll [--nn]] [--rr] [_f_i_r_s_t [_l_a_s_t]]
              _f_i_r_s_t and _l_a_s_t select commands  from  the  history.
              Commands  can  be  selected by history number, or a
              string specifying the most recent command  starting
              with  that string.  The --ll option lists the command



                        November 28, 1994                      24





KSH(1)                    User commands                    KSH(1)


              on stdout, and --nn inhibits the default command num-
              bers.   The  --rr  option  reverses  the order of the
              list.  Without --ll, the selected commands are edited
              by  the  editor specified with the --ee option, or if
              no --ee is specified, the  editor  specified  by  the
              FFCCEEDDIITT  parameter  (if  this  parameter is not set,
              //bbiinn//eedd is used), and then executed by the shell.

       ffcc --ee -- [--gg] [_o_l_d==_n_e_w] [_p_r_e_f_i_x]
              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 rr==''ffcc --ee --''.

       ffgg [_j_o_b ...]
              Resume  the specified job(s) in the foreground.  If
              no jobs are specified, %%++ is assumed.  This command
              is only available on systems which support job con-
              trol.  See Job Control below for more  information.

       ggeettooppttss _o_p_t_s_t_r_i_n_g _n_a_m_e [_a_r_g ...]
              ggeettooppttss  is  used  by shell procedures to parse the
              specified arguments (or positional  parameters,  if
              no  arguments  are  given)  and  to check for legal
              options.  _o_p_t_s_t_r_i_n_g  contains  the  option  letters
              that  ggeettooppttss is to recognize.  If a letter is fol-
              lowed by a colon, the option is expected to have an
              argument.   Arguments  containing  options must all
              start with either a -- or a ++, options that  do  not
              take arguments may be grouped in a single argument.
              If an option takes an argument and the option char-
              acter  is not the last character of the argument it
              is found in, the remainder of the argument is taken
              to  be  the  option's argument, otherwise, the next
              argument is the option's argument.

              Each time ggeettooppttss is invoked, it  places  the  next
              option in the shell parameter _n_a_m_e and the index of
              the next argument to  be  processed  in  the  shell
              parameter  OOPPTTIINNDD.   If  the  option was introduced
              with a ++, the option placed  in  _n_a_m_e  is  prefixed
              with  a  ++.   When  an option requires an argument,
              ggeettooppttss places it in the  shell  parameter  OOPPTTAARRGG.
              The  action taken when an illegal option or a miss-
              ing option argument is encountered depends on  _o_p_t_-
              _s_t_r_i_n_g: if it does not begin with a colon, an error
              message is printed on standard error and a question
              mark  is placed in _n_a_m_e; if ooppttssttrriinngg starts with a
              colon, no error message is printed, a question mark
              or  colon  is placed in _n_a_m_e, indicating an illegal
              option  or  missing  argument,  respectively,   and
              OOPPTTAARRGG  is  set to the option character that caused



                        November 28, 1994                      25





KSH(1)                    User commands                    KSH(1)


              the problem.

              When the end of the options is encountered, ggeettooppttss
              exits  with a non-zero exit status.  Options end at
              the first (non-option argument) argument that  does
              not  start  with  a  -,  or  when  a ---- argument is
              encountered.

              Option parsing can be reset by setting OOPPTTIINNDD to  1
              (this is done automatically whenever the shell or a
              shell procedure is invoked).

              Warning: Changing the value of the shell  parameter
              OOPPTTIINNDD  to a value other than 1, or parsing differ-
              ent sets of arguments without resetting OOPPTTIINNDD  may
              lead to unexpected results.

       hhaasshh [--rr] [_n_a_m_e _._._.]
              Without  arguments,  any  hashed executable command
              pathnames are listed.  The  --rr  option  causes  all
              hashed  commands to be removed from the hash table.
              Each _n_a_m_e is searched as if it where a command name
              and  added to the hash table if it is an executable
              command.

       jjoobbss [--llppnn] [_j_o_b ...]
              Display information about the specified jobs; if no
              jobs are specified, all jobs are displayed.  The --nn
              option causes information to be displayed only  for
              jobs that have changed state since the last notifi-
              cation.  If the --ll option is used,  the  process-id
              of  each  process  in a job is also listed.  The --pp
              option causes only the process group of each job to
              be  printed.   See Job Control below for the format
              of _j_o_b and the displayed job.

       kkiillll [--ss _s_i_g_n_a_m_e | --ssiiggnnuumm | --ssiiggnnaammee ] { _j_o_b | _p_i_d |
              --_p_g_r_p } ...
              Send the specified signal to  the  specified  jobs,
              process  ids,  or  process groups.  If no signal is
              specified, the signal TERM is sent.  If  a  job  is
              specified,  the signal is sent to the job's process
              group.  See Job Control below  for  the  format  of
              _j_o_b.

       kkiillll --ll [_e_x_i_t_-_s_t_a_t_u_s ...]
              Print  the name of the signal that killed a process
              which exited with the specified _e_x_i_t_-_s_t_a_t_u_ses.   If
              no  arguments are specified, a list of all the sig-
              nals, their numbers and a short description of them
              are printed.

       lleett [_e_x_p_r_e_s_s_i_o_n ...]
              Each   expression   is  evaluated,  see  Arithmetic



                        November 28, 1994                      26





KSH(1)                    User commands                    KSH(1)


              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
              expressions  may  need  to be quoted, (((( _e_x_p_r )))) is
              syntactic sugar for lleett ""_e_x_p_r"".

       pprriinntt [--nnpprrssuu_n || --RR [[--eenn]]]] [[_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 suppresses 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 using the --nn option.
              \ expansion may be inhibited with  the  --rr  option.
              The --ss option prints to the history file instead of
              standard output,  the  --uu  option  prints  to  file
              descriptor  _n (_n defaults to 1 if omitted), and the
              --pp  option  prints  to  the  co-process  (see   Co-
              Processes above).

              The  --RR  option is used to emulate, to some degree,
              the BSD echo command,  which  does  not  process  \
              sequences unless the --ee option is given.  As above,
              the --nn option suppresses the trailing newline.

       rreeaadd [--pprrssuu_n] [_p_a_r_a_m_e_t_e_r _._._.]
              Reads a line of input from standard input, separate
              the  line  into fields using the IIFFSS parameter (see
              Substitution above), and assign each field  to  the
              specified parameters.  If there are more parameters
              than fields, the extra parameters are set to  null,
              or  alternatively,  if  there  are more fields than
              parameters, the  last  parameter  is  assigned  the
              remaining   fields  (inclusive  of  any  separating
              spaces).  If no parameters are specified, the RREEPPLLYY
              parameter  is  used.   If  the input line ends in a
              backslash and the --rr option was not used, the back-
              slash  and  newline  are stripped and more input is
              read.  If no input is read, rreeaadd exits with a  non-
              zero status.

              A prompt, which is printed to standard error before
              any input is read, may be  specified  by  appending
              and  question  mark  and  the  prompt  to the first
              parameter (e.g., rreeaadd nnffoooo??''nnuummbbeerr ooff ffooooss:: '').

              The --uu_n and --pp options cause input to be read  from
              file   descriptor  _n  or  the  current  co-process,
              respectively.  If the --ss option is used,  input  is
              saved to the history file.

       rreeaaddoonnllyy [--pp] [_p_a_r_a_m_e_t_e_r[==_v_a_l_u_e]] ...
              Sets  the  readonly  attribute of the named parame-
              ters.  If values are given, parameters are  set  to



                        November 28, 1994                      27





KSH(1)                    User commands                    KSH(1)


              them  before setting the attribute.  Once a parame-
              ter is made readonly, it cannot be  unset  and  its
              value cannot be changed.

              If  no  parameters  are specified, the names of all
              parameters with the readonly attribute are  printed
              one  per  line,  unless  the  --pp option is used, in
              which case rreeaaddoonnllyy commands defining all  readonly
              parameters, including their values, are printed.

       rreettuurrnn [_s_t_a_t_u_s]
              Returns from a function or .. script, with exit sta-
              tus _s_t_a_t_u_s.  If no _s_t_a_t_u_s is given, the exit status
              of the last executed command is used.  If used out-
              side of a function or .. script,  it  has  the  same
              effect  as  eexxiitt.  Note that pdksh treats both pro-
              file and $$EENNVV files as

       sseett [++--aabbCCeeffhhkkmmnnppssuuvvxxXX] [++--oo [_o_p_t_i_o_n]] [++--AA _n_a_m_e] [----]
              [_a_r_g  ...]
              Set (--) or clear (++) a shell option:

               --AA                  Sets the elements of the array
                                   parameter  _n_a_m_e to _a_r_g ...; If
                                   --AA is used, the array is reset
                                   (i.e., emptied) first.
               --aa  aalllleexxppoorrtt       all new parameters are created
                                   with the export attribute
               --bb  nnoottiiffyy          Print  job  notification  mes-
                                   sages  asynchronously, instead
                                   of  just  before  the  prompt.
                                   Only  used  if  job control is
                                   enabled (--mm).
               --CC  nnoocclloobbbbeerr       Prevent  >>  redirection   from
                                   overwriting existing files (>>!!
                                   must be used to force an over-
                                   write).
               --ee  eerrrreexxiitt         Exit   as  soon  as  an  error
                                   occurs  or  a  command   fails
                                   (i.e.,  exits  with a non-zero
                                   status).  This does not  apply
                                   to  commands whose exit status
                                   is  explicitly  tested  by   a
                                   shell  construct  such  as iiff,
                                   uunnttiill, wwhhiillee, &&&& or ||||  state-
                                   ments.
               --ff  nnoogglloobb          Do  not  expand file name pat-
                                   terns.
               --hh  ttrraacckkaallll        Create tracked aliases for all
                                   executed commands (see Aliases
                                   above).   On  by  default  for
                                   non-interactive shells.





                        November 28, 1994                      28





KSH(1)                    User commands                    KSH(1)


               --ii  iinntteerraaccttiivvee     Enable interactive mode - this
                                   can only be set/unset when the
                                   shell is invoked.
               --kk  kkeeyywwoorrdd         Parameter assignments are rec-
                                   ognized anywhere in a command.
               --mm  mmoonniittoorr         Enable  job  control  (default
                                   for interactive shells).
               --nn  nnooeexxeecc          Do not execute any commands  -
                                   useful for checking the syntax
                                   of scripts (ignored if  inter-
                                   active).
               --pp  pprriivviilleeggeedd      Set automatically if, when the
                                   shell starts, the read uid  or
                                   gid  does not match the effec-
                                   tive uid or gid, respectively.
                                   See  Shell Startup above for a
                                   description   of   what   this
                                   means.
               --rr  rreessttrriicctteedd      Enable restricted mode -- this
                                   option can only be  used  when
                                   the  shell  is  invoked.   See
                                   Shell  Startup  above  for   a
                                   description   of   what   this
                                   means.
               --ss
               --ss  ssttddiinn           If  used  when  the  shell  is
                                   invoked,   commands  are  read
                                   from  standard   input.    Set
                                   automatically  if the shell is
                                   invoked with no arguments.

                                   When --ss is  used  in  the  sseett
                                   command,  it  causes the argu-
                                   ments  to  be  sorted   before
                                   assigning  them  to  the posi-
                                   tional parameters (or to array
                                   _n_a_m_e, if --AA is used).
               --uu  nnoouunnsseett         Referencing of an unset param-
                                   eter is treated as  an  error,
                                   unless  one  of  the --, ++ or ==
                                   modifiers is used.
               --vv  vveerrbboossee         Write shell input to  standard
                                   error as it is read.
               --xx  xxttrraaccee          Print  commands  and parameter
                                   assignments when they are exe-
                                   cuted,  preceded  by the value
                                   of PPSS44.
               --XX  mmaarrkkddiirrss        Mark directories with a trail-
                                   ing // during file name genera-
                                   tion.
                   bbggnniiccee          Background jobs are  run  with
                                   lower priority.





                        November 28, 1994                      29





KSH(1)                    User commands                    KSH(1)


                   bbrraacceeeexxppaanndd     Enable  brace  expansion (aka,
                                   alternation).
                   eemmaaccss           Enable BRL emacs-like  command
                                   line    editing   (interactive
                                   shells only); see Emacs Inter-
                                   active Input Line Editing.
                   ggmmaaccss           Enable   gmacs-like   (Gosling
                                   emacs)  command  line  editing
                                   (interactive   shells   only);
                                   currently identical  to  emacs
                                   editing  except that transpose
                                   (^T)  acts  slightly   differ-
                                   ently.
                   iiggnnoorreeeeooff       The  shell  will  not  exit on
                                   when end-of-file is read, eexxiitt
                                   must be used.
                   nnoolloogg           No  effect  -  in the original
                                   Korn  shell,   this   prevents
                                   function    definitions   from
                                   being stored  in  the  history
                                   file.
                   ppoossiixx           Enable  posix mode.  See POSIX
                                   Mode above.
                   vvii              Enable  vi-like  command  line
                                   editing   (interactive  shells
                                   only).
                   vviirraaww           No effect -  in  the  original
                                   Korn  shell,  unless viraw was
                                   set, the vi command line  mode
                                   would  let  the  tty driver do
                                   the work until  ESC  (^[)  was
                                   entered.   pdksh  is always in
                                   viraw mode.
                   vvii--sshhooww88        Prefix  characters  with   the
                                   eighth  bit set with `M-'.  If
                                   this option is not set,  char-
                                   acters  in  the  range 128-160
                                   are printed as is,  which  may
                                   cause problems.
                   vvii--ttaabbccoommpplleettee  In vi command line editing, do
                                   file name completion when  tab
                                   (^I)   is  entered  in  insert
                                   mode.

              These options can also be used upon  invocation  of
              the shell.  The current set of options can be found
              in the parameter --.  Remaining arguments,  if  any,
              are  positional  parameters  and  are  assigned, in
              order, to the positional parameters  (i.e.,  11,  22,
              etc.).   If options are ended with ---- and there are
              no remaining arguments, all  positional  parameters
              are cleared.  If no options or arguments are given,
              then the values of  all  names  are  printed.   For
              unknown  historical  reasons,  a  lone  -- option is



                        November 28, 1994                      30





KSH(1)                    User commands                    KSH(1)


              treated specially: it clears both  the  --xx  and  --vv
              options.

       sshhiifftt [_n_u_m_b_e_r]
              The positional parameters _n_u_m_b_e_r, _n_u_m_b_e_r_+_1 etc. are
              renamed to 11, 22, etc.  _n_u_m_b_e_r defaults to 1.

       tteesstt _e_x_p_r_e_s_s_i_o_n
              tteesstt evaluates the _e_x_p_r_e_s_s_i_o_n and returns zero sta-
              tus  if true, and non-zero status otherwise.  It is
              normally used as the condition command  of  iiff  and
              wwhhiillee  statements.  The following basic expressions
              are available:

               --rr _f_i_l_e              _f_i_l_e exists and is readable
               --ww _f_i_l_e              _f_i_l_e exists and is writable
               --xx _f_i_l_e              _f_i_l_e  exists  and  is   exe-
                                    cutable
               --aa _f_i_l_e              _f_i_l_e exists
               --ee _f_i_l_e              _f_i_l_e exists
               --ff _f_i_l_e              _f_i_l_e is a regular file
               --dd _f_i_l_e              _f_i_l_e is a directory
               --cc _f_i_l_e              _f_i_l_e  is a character special
                                    device
               --bb _f_i_l_e              _f_i_l_e  is  a  block   special
                                    device
               --pp _f_i_l_e              _f_i_l_e is a named pipe
               --uu _f_i_l_e              _f_i_l_e's  mode  has setuid bit
                                    set
               --gg _f_i_l_e              _f_i_l_e's mode has  setgid  bit
                                    set
               --kk _f_i_l_e              _f_i_l_e's  mode  has sticky bit
                                    set
               --ss _f_i_l_e              _f_i_l_e is not empty
               --OO _f_i_l_e              _f_i_l_e's owner is the  shell's
                                    effective user-ID
               --GG _f_i_l_e              _f_i_l_e's  group is the shell's
                                    effective group-ID
               --hh _f_i_l_e              _f_i_l_e is a symbolic link
               --HH _f_i_l_e              _f_i_l_e is a context  dependent
                                    directory  (only  useful  on
                                    HP-UX)
               --LL _f_i_l_e              _f_i_l_e is a symbolic link
               --SS _f_i_l_e              _f_i_l_e is a socket
               --oo _o_p_t_i_o_n            shell _o_p_t_i_o_n is set (see sseett
                                    command  above  for  list of
                                    options)
               _f_i_l_e --nntt _f_i_l_e        first  _f_i_l_e  is  newer  than
                                    second _f_i_l_e
               _f_i_l_e --oott _f_i_l_e        first  _f_i_l_e  is  older  than
                                    second _f_i_l_e
               _f_i_l_e --eeff _f_i_l_e        first _f_i_l_e is the same  file
                                    as second _f_i_l_e




                        November 28, 1994                      31





KSH(1)                    User commands                    KSH(1)


               --tt [[_f_d]]              file  descriptor  is  a  tty
                                    device.  Default value of _f_d
                                    is 1.
               _s_t_r_i_n_g               _s_t_r_i_n_g is not empty
               --zz _s_t_r_i_n_g            _s_t_r_i_n_g is empty
               --nn _s_t_r_i_n_g            _s_t_r_i_n_g is not empty
               _s_t_r_i_n_g == _s_t_r_i_n_g      strings are equal
               _s_t_r_i_n_g !!== _s_t_r_i_n_g     strings are not equal
               _n_u_m_b_e_r --eeqq _n_u_m_b_e_r    numbers compare equal
               _n_u_m_b_e_r --nnee _n_u_m_b_e_r    numbers compare not equal
               _n_u_m_b_e_r --ggee _n_u_m_b_e_r    numbers compare greater than
                                    or equal
               _n_u_m_b_e_r --ggtt _n_u_m_b_e_r    numbers compare greater than
               _n_u_m_b_e_r --llee _n_u_m_b_e_r    numbers compare less than or
                                    equal
               _n_u_m_b_e_r --lltt _n_u_m_b_e_r    numbers compare less than

              The above basic expressions, in which unary  opera-
              tors  have precedence over binary operators, may be
              combined with the following  operators  (listed  in
              increasing order of precedence):

               _e_x_p_r --oo _e_x_p_r    logical or
               _e_x_p_r --aa _e_x_p_r    logical and
               !! _e_x_p_r          logical not
               (( _e_x_p_r ))        grouping

              Note  that some special rules are applied (courtesy
              of POSIX) if the number of arguments to tteesstt  or  [[
              ... ]] is less than five: if leading !! arguments can
              be stripped such that  only  one  argument  remains
              then a string length test is performed (again, even
              if the argument is a unary operator); if leading  !!
              arguments can be stripped such that three arguments
              remain and the second argument is a  binary  opera-
              tor,  then  the binary operation is performed (even
              if first argument is a unary operator, including an
              unstripped !!).

              NNoottee::  A common mistake is to use iiff [[ $$ffoooo == bbaarr ]]
              which fails if parameter ffoooo is null or  unset,  if
              it  has  embedded spaces (i.e., IIFFSS characters), or
              if it is a unary operator like !! or --nn.  Use  tests
              like iiff [[ ""XX$$ffoooo"" == XXbbaarr ]] instead.

       ttiimmeess  Print the accumulated user and system times used by
              the shell and by processes which have  exited  that
              the shell started.

       ttrraapp [_h_a_n_d_l_e_r _s_i_g_n_a_l _._._.]
              Sets  trap  handler that is to be executed when any
              of the specified signals are received.  HHaannddlleerr  is
              either a null string, indicating the signals are to
              be  ignored,  a  minus  (--),  indicating  that  the



                        November 28, 1994                      32





KSH(1)                    User commands                    KSH(1)


              default  action is to be taken for the signals (see
              signal(2 or 3)), or a string containing shell  com-
              mands  to  be  evaluated  and executed at the first
              opportunity (i.e., when the  current  command  com-
              pletes,  or  before  printing  the next PPSS11 prompt)
              after receipt of one of the signals.  SSiiggnnaall is the
              name of a signal (e.g., PIPE or ALRM) or the number
              of the signal (see kkiillll --ll command  above).   There
              are  two  special  signals: EEXXIITT (also known as 00),
              which is executed when the shell is about to  exit,
              and EERRRR which is executed after an error occurs (an
              error is something that would cause  the  shell  to
              exit if the --ee or eerrrreexxiitt option were set - see sseett
              command above).  EEXXIITT handlers are executed in  the
              environment  of  the  last  executed command.  Note
              that for non-interactive shells, the  trap  handler
              cannot  be  changed  for  signals that were ignored
              when the shell started.

              With no arguments, ttrraapp lists, as a series of  ttrraapp
              commands,  the current state of the traps that have
              been set since the shell started.

              The original Korn shell's DDEEBBUUGG trap and  the  han-
              dling  of  EERRRR  and EEXXIITT traps in functions are not
              yet implemented.

       ttrruuee   A command that exits with a zero value.

       ttyyppeesseett [[+-Ulrtux] [--LL[_n]] [--RR[_n]] [--ZZ[_n]] [--ii[_n]] | --ff
              [--ttuuxx]] [_n_a_m_e[==_v_a_l_u_e] ...]
              Display or set parameter attributes.  With no  _n_a_m_e
              arguments,  parameter  attributes are displayed: if
              no options arg used, the current attributes of  all
              parameters  are  printed as typeset commands; if an
              option is given (or -- with no  option  letter)  all
              parameters  and  their  values  with  the specified
              attributes are printed; if options  are  introduced
              with ++, parameter values are not printed.

              If  _n_a_m_e arguments are given, the attributes of the
              named parameters are set (--) or cleared (++).   Val-
              ues for parameters may optionally be specified.  If
              typeset is used inside a function, any  newly  cre-
              ated parameters are local to the function.

              When --ff is used, typeset operates on the attributes
              of functions.  As with parameters, if no _n_a_m_es  are
              given,  functions  are  listed  with  their  values
              (i.e., definitions) unless options  are  introduced
              with  ++,  in which case only the function names are
              reported.





                        November 28, 1994                      33





KSH(1)                    User commands                    KSH(1)


               --LL_n  Left justify attribute: _n specifies the field
                    width.   If  _n  is not specified, the current
                    width of a parameter (or  the  width  of  its
                    first assigned value) is used.  Leading white
                    space (and zeros, if used with the --ZZ option)
                    is stripped.  If necessary, values are either
                    truncated or space padded to  fit  the  field
                    width.
               --RR_n  Right  justify  attribute:  _n  specifies  the
                    field width.  If _n is not specified, the cur-
                    rent  width  of  a parameter (or the width of
                    its first assigned value) is used.   Trailing
                    white space are stripped.  If necessary, val-
                    ues are either stripped of leading characters
                    or  space  padded  to make them fit the field
                    width.
               --ZZ_n  Zero fill attribute: if not combined with --LL,
                    this  is  the same as --RR, except zero padding
                    is used instead of space padding.
               --ii_n  integer attribute: _n specifies  the  base  to
                    use when displaying the integer (if not spec-
                    ified, the base given in the first assignment
                    is used).  Parameters with this attribute may
                    be  assigned  values  containing   arithmetic
                    expressions.
               --UU   unsigned   integer  attribute:  integers  are
                    printed as unsigned values (only useful  when
                    combined with the --ii option).  This option is
                    not in the original Korn shell.
               --ff   Function mode: display or set  functions  and
                    their attributes, instead of parameters.
               --ll   Lower case attribute: all  upper case charac-
                    ters in values are converted to  lower  case.
                    (In  the  original Korn shell, this parameter
                    meant `long integer' when used  with  the  --ii
                    option).
               --rr   Readonly  attribute: parameters with the this
                    attribute may not be assigned  to  or  unset.
                    Once  this  attribute  is  set, it can not be
                    turned off.
               --tt   Tag attribute: has no meaning to  the  shell;
                    provided for application use.

                    For  functions,  --tt  is  the trace attribute.
                    When functions with the trace  attribute  are
                    executed,  the  xxttrraaccee  (--xx)  shell option is
                    temporarily turned on.










                        November 28, 1994                      34





KSH(1)                    User commands                    KSH(1)


               --uu   Upper case attribute: all lower case  charac-
                    ters  in  values are converted to upper case.
                    (In the original Korn shell,  this  parameter
                    meant  `unsigned  integer' when used with the
                    --ii option, which  meant  upper  case  letters
                    would  never  be  used for bases greater than
                    10.  See the --UU option).

                    For functions, --uu is the undefined attribute.
                    See  Functions  above for the implications of
                    this.
               --xx   Export attribute: parameters  (or  functions)
                    are placed in the environment of any executed
                    commands.  Exported functions are not  imple-
                    mented yet.

       uulliimmiitt [--aaccddffHHmmnnssSSttvvww] [_v_a_l_u_e]
              Display  or  set process limits.  If no options are
              used, the file size limit (--ff) is assumed.   vvaalluuee,
              if  specified,  may  be  either  be  an  arithmetic
              expression  or  the  word  uunnlliimmiitteedd.   The  limits
              affect  the  shell and any processes created by the
              shell after a limit is  imposed.   Note  that  some
              systems  may  not allow limits to be increased once
              they are set.  Also note that the types  of  limits
              available  are system dependent - some systems have
              only the --ff limit.

              --aa     Displays all limits.

              --HH     Set the hard limit only (default is  to  set
                     both hard and soft limits).

              --SS     Set  the  soft limit only (default is to set
                     both hard and soft limits).

              --cc     Impose a size limit of _n blocks on the  size
                     of core dumps.

              --dd     Impose  a size limit of _n kbytes on the size
                     of the data area.

              --ff     Impose a size limit of  _n  blocks  on  files
                     written by the shell and its child processes
                     (files of any size may be read).

              --mm     Impose a limit of _n kbytes on the amount  of
                     physical memory used.

              --nn     Impose  a  limit  of _n file descriptors that
                     can be open at once.

              --ss     Impose a size limit of _n kbytes on the  size
                     of the stack area.



                        November 28, 1994                      35





KSH(1)                    User commands                    KSH(1)


              --tt     Impose  a time limit of _n seconds to be used
                     by each process.

              --vv     Impose a limit of _n kbytes on the amount  of
                     virtual memory used; on some systems this is
                     the maximum allowable  virtual  address  (in
                     bytes, not kbytes).

              --ww     Impose  a limit of _n kbytes on the amount of
                     swap space used.

              As far as uulliimmiitt  is  concerned,  a  block  is  512
              bytes.

       uummaasskk [--SS] [_m_a_s_k]
              Display  or  set the file permission creation mask,
              or umask (see _u_m_a_s_k(2)).  If the --SS option is used,
              the mask displayed or set is symbolic, otherwise it
              is an octal number.

              Symbolic masks are like those used by _c_h_m_o_d(1):
                          [uuggooaa]{{==++--}{rrwwxx}*}+[,,...]
              in which the first group of characters is  the  _w_h_o
              part, the second group is the _o_p part, and the last
              group is the _p_e_r_m part.   The  _w_h_o  part  specifies
              which  part  of  the  umask is to be modified.  The
              letters mean:

                      uu      the user permissions

                      gg      the group permissions

                      oo      the  other  permissions   (non-user,
                             non-group)

                      aa      all  permissions  (user,  group  and
                             other)

              The _o_p part indicates how the _w_h_o  permissions  are
              to be modified:

                      ==      set

                      ++      added to

                      --      removed from

              The _p_e_r_m part specifies which permissions are to be
              set, added or removed:

                      rr      read permission

                      ww      write permission




                        November 28, 1994                      36





KSH(1)                    User commands                    KSH(1)


                      xx      execute permission

              When symbolic masks are used,  they  describe  what
              permissions  may  be  made available (as opposed to
              octal masks in which a set  bit  means  the  corre-
              sponding   bit   is   to   be  cleared).   Example:
              `ug=rwx,o=' sets the mask  so  files  will  not  be
              readable,  writable  or executable by `others', and
              is equivalent (on most systems) to the  octal  mask
              `07'.

       uunnaalliiaass [--aaddtt] [_n_a_m_e_1 ...]
              The  aliases  for  the given names are removed.  If
              the --aa option is used, all aliases are removed.  If
              the --tt or --dd options are used, the indicated opera-
              tions are  carried  out  on  tracked  or  directory
              aliases, respectively.

       uunnsseett [--ffvv] _p_a_r_a_m_e_t_e_r ...
              Unset  the  named  parameters  (--vv, the default) or
              functions (--ff).

       wwaaiitt [_j_o_b]
              Wait for the specified job(s) to finish.  The  exit
              status  of  wait is that of the last specified job:
              if the last job is killed by  a  signal,  the  exit
              status  is 128 + the number of the signal (see kkiillll
              --ll _e_x_i_t_-_s_t_a_t_u_s above); if the  last  specified  job
              can't  be  found  (because it never existed, or had
              already finished), the exit status of wait is  127.
              See  Job Control below for the format of _j_o_b.  WWaaiitt
              will return if a signal for which a trap  has  been
              set is received, or if a HUP, INT or QUIT signal is
              received.

              If no jobs are specified, wwaaiitt waits for  all  cur-
              rently  running  jobs  (if any) to finish and exits
              with a zero status.  If job monitoring is  enabled,
              the  completion  status of jobs is printed (this is
              not the case when jobs are explicitly specified).

       wwhheennccee [--ppvv] [name ...]
              For each name, the type of command is listed  (key-
              word,  built-in,  alias, function, tracked alias or
              executable).  If the --pp  option  is  used,  a  path
              search  done even if _n_a_m_e is a keyword, alias, etc.
              Without the --vv option, wwhheennccee is the same  as  ccoomm--
              mmaanndd --vv; with the --VV option, it is the same as ccoomm--
              mmaanndd --VV.  Note that for wwhheennccee, the --pp option  does
              not  affect  the  search  path used, as it does for
              ccoommmmaanndd.  If the type of one or more of  the  names
              could  not  be  determined, the exit status is non-
              zero.




                        November 28, 1994                      37





KSH(1)                    User commands                    KSH(1)


   JJoobb CCoonnttrrooll
       Job control refers to the shell's ability to  monitor  and
       control  jjoobbss,  which are processes or groups of processes
       created for commands or  pipelines.   At  a  minimum,  the
       shell  keeps  track of the status of the background (i.e.,
       asynchronous) jobs that currently exist; this  information
       can  be  displayed using the jjoobbss command.  If job control
       is fully enabled (using sseett --mm or sseett --oo mmoonniittoorr),  as  it
       is  for  interactive  shells,  the  processes of a job are
       placed in their own process group, foreground jobs can  be
       stopped  by typing the suspend character from the terminal
       (normally ^Z), jobs can be restarted in either  the  fore-
       ground  or  background,  using  the  ffgg  and  bbgg commands,
       respectively, and the state of the terminal  is  saved  or
       restored  when  a  foreground job is stopped or restarted,
       respectively.

       Note that only commands that create processes (e.g., asyn-
       chronous  commands,  subshell  commands,  and non-builtin,
       non-function commands) can be stopped; commands like  rreeaadd
       cannot be.

       When  a  job is created, it is assigned a job-number.  For
       interactive shells, this number is  printed  inside  [[..]],
       followed  by  the  process-ids of the processes in the job
       when an  asynchronous  command  is  run.   A  job  may  be
       referred to in bbgg, ffgg, jjoobbss, kkiillll and wwaaiitt commands either
       by the process id of  the  last  process  in  the  command
       pipeline  (as  stored in the $$!! parameter) or by prefixing
       the job-number with a percent  sign  (%%).   Other  percent
       sequences can also be used to refer to jobs:

        %%++          The  most  recently stopped job, or, if there
                    are no stopped jobs, the oldest running  job.
        %%%%, %%       Same as %%++.
        %%--          The  job  that  would  be  the %%++ job, if the
                    later did not exist.
        %%_n          The job with job-number _n.
        %%??_s_t_r_i_n_g    The job  containing  the  string  _s_t_r_i_n_g  (an
                    error occurs if multiple jobs are matched).
        %%_s_t_r_i_n_g     The job starting with string _s_t_r_i_n_g (an error
                    occurs if multiple jobs are matched).

       When a job changes state (e.g., a background job  finishes
       or  foreground  job is stopped), the shell prints the fol-
       lowing status information:
                      [[_n_u_m_b_e_r]] _f_l_a_g _s_t_a_t_u_s _c_o_m_m_a_n_d
       where

        _n_u_m_b_e_r
              is the job-number of the job.

        _f_l_a_g  is ++ or -- if the job is the %%++ or %%--  job,  respec-
              tively, or space if it is neither.



                        November 28, 1994                      38





KSH(1)                    User commands                    KSH(1)


        _s_t_a_t_u_s
              indicates the current state of the job and can be

              RRuunnnniinngg
                     the  job has neither stopped or exited (note
                     that running does not necessarily mean  con-
                     suming  CPU  time  --  the  process could be
                     blocked waiting for some event).

              DDoonnee [((_n_u_m_b_e_r))]
                     the job exited. _n_u_m_b_e_r is the exit status of
                     the  job,  which is omitted if the status is
                     zero.

              SSttooppppeedd [((_s_i_g_n_a_l))]
                     the job was stopped by the indicated  _s_i_g_n_a_l
                     (if  no signal is given, the job was stopped
                     by SIGTSTP).

              _s_i_g_n_a_l_-_d_e_s_c_r_i_p_t_i_o_n [((ccoorree dduummppeedd))]
                     the  job  was  killed  by  a  signal  (e.g.,
                     Memory fault,  Hangup,  etc.  -- use kkiillll --ll
                     for a list  of  signal  descriptions).   The
                     ((ccoorree dduummppeedd))  message indicates the process
                     created a core file.

        _c_o_m_m_a_n_d
              is the command that created the process.  If  there
              are  multiple  processes in the job, then each pro-
              cess will have a line showing its _c_o_m_m_a_n_d and  pos-
              sibly  its _s_t_a_t_u_s, if it is different from the sta-
              tus of the previous process.

   EEmmaaccss IInntteerraaccttiivvee IInnppuutt LLiinnee EEddiittiinngg
       When the eemmaaccss option is set, interactive input line edit-
       ing  is enabled.  WWaarrnniinngg: This mode is slightly different
       from the emacs mode in the original Korn shell and the 8th
       bit is stripped in emacs mode.  In this mode various edit-
       ing commands (typically bound to one or more control char-
       acters) cause immediate actions without waiting for a new-
       line.  Several editing commands are  bound  to  particular
       control  characters when the shell is invoked; these bind-
       ings can be changed using the following commands:

       bbiinndd   The current bindings are listed.

       bbiinndd _s_t_r_i_n_g==[_e_d_i_t_i_n_g_-_c_o_m_m_a_n_d]
              The specified editing command is bound to the given
              ssttrriinngg, which should consist of a control character
              (which may be written  using  caret  notation  ^^_X),
              optionally  preceded by one of the two prefix char-
              acters.  Future input of the _s_t_r_i_n_g will cause  the
              editing  command  to  be immediately invoked.  Note
              that although only two prefix  characters  (usually



                        November 28, 1994                      39





KSH(1)                    User commands                    KSH(1)


              ESC  and  ^X)  are  supported, some multi-character
              sequences can be supported.   The  following  binds
              the arrow keys on an ANSI terminal, or xterm (these
              are in  the  default  bindings).   Of  course  some
              escape sequences won't work out quite this nicely:

              bbiinndd ''^^[[[[''==pprreeffiixx--22
              bbiinndd ''^^XXAA''==uupp--hhiissttoorryy
              bbiinndd ''^^XXBB''==ddoowwnn--hhiissttoorryy
              bbiinndd ''^^XXCC''==ffoorrwwaarrdd--cchhaarr
              bbiinndd ''^^XXDD''==bbaacckkwwaarrdd--cchhaarr

       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 afterwards be imme-
              diately replaced by the  given  _s_u_b_s_t_i_t_u_t_e  string,
              which may contain editing commands.

       The  following  editing  commands 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  described.   Note  that editing command names are used
       only with the bbiinndd  command.   Furthermore,  many  editing
       commands  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
       (e.g., 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  character 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; words are delimited by the current setting of
              IIFFSS.

       bbeeggiinnnniinngg--ooff--lliinnee ^^AA
              Moves  the  cursor  to  the beginning of the edited
              input line.

       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 //



                        November 28, 1994                      40





KSH(1)                    User commands                    KSH(1)


              is appended.  If there is no hashed command or file
              name with the current partial word as its prefix, a
              bell  character  is output (usually causing a audio
              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  com-
              mand  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^^XX
              Automatically completes as much as is unique of the
              file  name having the partial word up to the cursor
              as its prefix, as in the ccoommpplleettee command described
              above.

       ccooppyy--llaasstt--aarrgg ^^[[__
              The  last  word of the previous 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
              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 performed.

       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.





                        November 28, 1994                      41





KSH(1)                    User commands                    KSH(1)


       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, columnated list of hashed command
              names or file names (if any) that can complete  the
              partial  word  containing  the  cursor.   Directory
              names have // appended to them, and executable  file
              names are followed by a **.

       lliisstt--ccoommmmaanndd ^^XX??
              Prints  a sorted, columnated list of hashed command
              names (if any) that can complete the  partial  word
              containing the cursor.

       lliisstt--ffiillee ^^XX^^YY
              Prints  a sorted, columnated list of file names (if
              any) that can complete the partial word  containing
              the  cursor.   File type indicators are appended as
              described under lliisstt above.

       nneewwlliinnee ^^JJ

       nneewwlliinnee ^^MM
              Causes the current input line to  be  processed  by
              the shell.  The current cursor position may be any-
              where 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.



                        November 28, 1994                      42





KSH(1)                    User commands                    KSH(1)


       nnoo--oopp QQUUIITT
              This does nothing.

       pprreeffiixx--11 ^^[[
              Introduces a 2-character command sequence.

       pprreeffiixx--22 ^^XX

       pprreeffiixx--22 ^^[[[[
              Introduces a 2-character command sequence.

       qquuoottee ^^^^
              The  following  character is taken literally rather
              than as an editing command.

       rreeddrraaww ^^LL
              Reprints the prompt string and  the  current  input
              line.

       sseeaarrcchh--cchhaarraacctteerr ^^]]
              Search  forward  in  the  current line for the next
              keyboard character.

       sseeaarrcchh--hhiissttoorryy ^^RR
              Enter incremental search mode.  The  internal  his-
              tory list is searched backwards for commands match-
              ing the input.  An initial ^^ in the  search  string
              anchors  the  search.   The  abort  key  will leave
              search mode.  Other commands will be executed after
              leaving  search  mode.   Successive  sseeaarrcchh--hhiissttoorryy
              commands continue searching backward  to  the  next
              previous  occurrence  of  the pattern.  The history
              buffer retains only a finite number of  lines;  the
              oldest are discarded as necessary.

       sseett--mmaarrkk--ccoommmmaanndd ^^[[<space>
              Set the mark at the cursor position.

       ssttuuffff  On  systems supporting it, pushes the bound charac-
              ter back onto  the  terminal  input  where  it  may
              receive special processing by the terminal handler.
              This is useful for the BRL ^^TT mini-systat  feature,
              for example.

       ssttuuffff--rreesseett
              Acts  like  ssttuuffff, then aborts input the same as an
              interrupt.

       ttrraannssppoossee--cchhaarrss ^^TT
              If at the end of line, or if the  ggmmaaccss  option  is
              set,  this  exchanges  the two previous characters;
              otherwise, it exchanges the  previous  and  current
              characters  and  moves  the cursor one character to
              the right.



                        November 28, 1994                      43





KSH(1)                    User commands                    KSH(1)


       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  previous killed text
              string.

       vveerrssiioonn ^^VV
              Display the  version  of  ksh.   The  current  edit
              buffer  is  restored  as soon as any key is pressed
              (the key is then processed).

   VVii IInntteerraaccttiivvee IInnppuutt LLiinnee EEddiittiinngg
       The vi command line editor in ksh has basically  the  same
       commands  as the vi editor (see _v_i(1)), with the following
       exceptions:

         +o    you start out in insert mode,

         +o    there are file name completion commands (==,  \\,  **,
              ^^XX, ^^EE, ^^FF and, optionally, ^^II),

         +o    the  __  command is different (in ksh it is the last
              argument command, in vi it goes to the start of the
              current line),

         +o    the // and GG commands move in the opposite direction
              as the jj command

         +o    and commands which don't make  sense  in  a  single
              line editor aren't available (e.g., screen movement
              commands, ex :: commands, etc.).

       Note that the ^^XX stands for control-X; also <<eesscc>>, <<ssppaaccee>>
       and <<ttaabb>> are used for escape, space and tab, respectively
       (no kidding).

       Like vi, there are two  modes:  insert  mode  and  command
       mode.   In  insert mode, most characters are simply put in
       the buffer at the current  cursor  position  as  they  are
       typed, however, some characters are treated specially.  In
       particular, the following characters are taken  from  cur-
       rent tty settings (see _s_t_t_y(1)) and have their usual mean-
       ing (normal values are in parentheses): kill  (^^UU),  erase
       (^^??),  werase (^^WW), eof (^^DD), intr (^^CC) and quit (^^\\).  In
       addition to the above, the following characters  are  also
       treated specially in insert mode:




                        November 28, 1994                      44





KSH(1)                    User commands                    KSH(1)


        ^^HH          erases previous character
        ^^VV          literal next: the next character typed is not
                    treated specially (can be used to insert  the
                    characters being described here)
        ^^JJ ^^MM       end of line: the current line is read, parsed
                    and executed by the shell
        <<eesscc>>       puts the editor in command mode (see below)
        ^^EE          file name enumeration (see below)
        ^^FF          file name completion (see below)
        ^^XX          file name expansion (see below)
        <<ttaabb>>       optional file name  completion  (see  below),
                    enabled with sseett --oo vvii--ttaabbccoommpplleettee

       If  a  line  is  longer that the screen width (see CCOOLLUUMMNNSS
       parameter), a >>, ++ or << character is displayed in the last
       column  indicating  that  there are more characters after,
       before and after, or before the current position,  respec-
       tively.  The line is scrolled horizontally as necessary.

       In  command  mode, each character is interpreted as a com-
       mand.  Characters that don't correspond to  commands,  are
       illegal  combinations  of  commands  or  are commands that
       can't be carried out all cause beeps.   In  the  following
       command  descriptions,  a  _n  indicates the command may be
       prefixed by a number (e.g., 1100ll  moves  right  10  charac-
       ters);  if  no number prefix is used, _n is assumed to be 1
       unless otherwise specified.  The term  `current  position'
       refers  to the position between the cursor and the charac-
       ter preceding the cursor.  A `word' is a sequence of  let-
       ters,  digits  and  underscore characters or a sequence of
       non-letter,  non-digit,  non-underscore,   non-white-space
       characters  (e.g.,  ab2*&^ contains two words) and a `big-
       word' is a sequence of non-white-space characters.

       Special ksh vi commands
              The following commands are not in, or are different
              from, the normal vi file editor:

              _n__     insert  a space followed by the _nth big-word
                     from the last command in the history at  the
                     current position and enter insert mode; if _n
                     is not specified, the last word is inserted.

              ##      insert  the  comment  character  (##)  at the
                     start of the current  line  and  return  the
                     line to the shell (equivalent to II##^^JJ).

              _ngg     like  GG,  except  if  _n is not specified, it
                     goes to the most recent remembered line.

              _nvv     edit line _n using the vi editor; if _n is not
                     specified,  the current line is edited.  The
                     actual   command   executed   is   `ffcc    --ee
                     $${{VVIISSUUAALL::--$${{EEDDIITTOORR::--vvii}}}} _n'.



                        November 28, 1994                      45





KSH(1)                    User commands                    KSH(1)


              ** and ^^XX
                     file  name  expansion:  replace  the current
                     big-word with the words obtained by  append-
                     ing a * to it and doing file name expansion.
                     After expansion, the cursor is  placed  just
                     past  the  last  word  and  the editor is in
                     insert mode.

              \\ and ^^FF
                     file name completion:  replace  the  current
                     big-word   with  the  longest  unique  match
                     obtained after performing file  name  expan-
                     sion.

              == and ^^EE
                     file  name  enumeration:  list all the files
                     that match the current big-word.

       Intra-line movement commands

              _nhh and _n^^HH
                     move left _n characters.

              _nll and _n<<ssppaaccee>>
                     move right _n characters.

              00      move to column 0.

              ^^      move to the first non-space character.

              _n||     move to column _n.

              $$      move to the last character.

              _nbb     move back _n words.

              _nBB     move back _n big-words.

              _nff     move forward _n words.

              _nFF     move forward _n big-words.

              _nee     move forward to the end the word, _n times.

              _nEE     move forward to  the  end  the  big-word,  _n
                     times.

              %%      find match: the editor looks forward for the
                     nearest parenthesis, bracket  or  brace  and
                     then  moves the to the matching parenthesis,
                     bracket or brace.

              _nff_c    move forward to the _nth  occurrence  of  the
                     character _c.



                        November 28, 1994                      46





KSH(1)                    User commands                    KSH(1)


              _nFF_c    move  backward  to the _nth occurrence of the
                     character _c.

              _ntt_c    move forward to just before the  _nth  occur-
                     rence of the character _c.

              _nTT_c    move  backward to just before the _nth occur-
                     rence of the character _c.

              _n;;     repeats the last ff, FF, tt or TT command.

              _n,,     repeats the last ff, FF, tt or TT  command,  but
                     moves in the opposite direction.

       Inter-line movement commands

              _njj and _n++ and _n^^NN
                     move to the _nth next line in the history.

              _nkk and _n-- and _n^^PP
                     move  to  the  _nth previous line in the his-
                     tory.

              _nGG     move to line _n in the history; if _n  is  not
                     specified,  the number first remembered line
                     is used.

              _ngg     like GG, except if _n  is  not  specified,  it
                     goes to the most recent remembered line.

              _n//_s_t_r_i_n_g
                     search  backward through the history for the
                     _nth line containing _s_t_r_i_n_g; if _s_t_r_i_n_g starts
                     with  ^^,  the  remainder  of the string must
                     appear at the start of the history line  for
                     it to match.

              _n??_s_t_r_i_n_g
                     same   as  //,  except  it  searches  forward
                     through the history.

              _nnn     search for the _nth occurrence  of  the  last
                     search  string;  the direction of the search
                     is the same as the last search.

              _nNN     search for the _nth occurrence  of  the  last
                     search  string;  the direction of the search
                     is the opposite of the last search.

       Edit commands

              _naa     append text _n times: goes into  insert  mode
                     just after the current position.  The append
                     is only replicated if command  mode  is  re-



                        November 28, 1994                      47





KSH(1)                    User commands                    KSH(1)


                     entered (i.e., <esc> is used).

              _nAA     same  as  aa, except it appends at the end of
                     the line.

              _nii     insert text _n times: goes into  insert  mode
                     at  the  current position.  The insertion is
                     only  replicated  if  command  mode  is  re-
                     entered (i.e., <esc> is used).

              _nII     same as ii, except the insertion is done just
                     before the first non-blank character.

              _nss     substitute  the  next  _n  characters  (i.e.,
                     delete  the  characters  and  go into insert
                     mode).

              SS      substitute whole line: all  characters  from
                     the  first non-blank character to the end of
                     line are deleted and insert mode is entered.

              _ncc_m_o_v_e_-_c_m_d
                     change  from  the  current  position  to the
                     position resulting from _n  _m_o_v_e_-_c_m_ds  (i.e.,
                     delete  the  indicated  region  and  go into
                     insert mode); if _m_o_v_e_-_c_m_d  is  cc,  the  line
                     starting  from the first non-blank character
                     is changed.

              CC      change from the current position to the  end
                     of  the line (i.e., delete to the end of the
                     line and go into insert mode).

              _nxx     delete the next _n characters.

              _nXX     delete the previous _n characters.

              _nDD     delete to the end of the line.

              _ndd_m_o_v_e_-_c_m_d
                     delete from  the  current  position  to  the
                     position  resulting  from _m_o_v_e_-_c_m_d; _m_o_v_e_-_c_m_d
                     is a movement command (see above) or  dd,  in
                     which case the current line is deleted.

              _nrr_c    replace the next _n characters with the char-
                     acter _c.

              _nRR     replace: enter  insert  mode  but  overwrite
                     existing  characters  instead  of  inserting
                     before existing characters.  The replacement
                     is repeated _n times.

              _n~~     change the case of the next _n characters.



                        November 28, 1994                      48





KSH(1)                    User commands                    KSH(1)


              _nyy_m_o_v_e_-_c_m_d
                     yank  from the current position to the posi-
                     tion resulting from  _n  _m_o_v_e_-_c_m_ds  into  the
                     yank  buffer;  if  _m_o_v_e_-_c_m_d  is yy, the whole
                     line is yanked.

              YY      yank from the current position to the end of
                     the line.

              _npp     paste  the  contents of the yank buffer just
                     after the current position, _n times.

              _nPP     same as pp, except the buffer  is  pasted  at
                     the current position.

       Miscellaneous vi commands

              ^^JJ and ^^MM
                     the  current  line  is read, parsed and exe-
                     cuted by the shell.

              ^^LL and ^^RR
                     redraw the current line.

              _n..     redo the last edit command _n times.

              uu      undo the last edit command.

              _i_n_t_r and _q_u_i_t
                     the interrupt and quit  terminal  characters
                     cause  the  current line to be deleted and a
                     new prompt to be printed.

       Missing vi commands
              The following vi commands are in the original  Korn
              shell, but are not yet in pdksh:

              UU      undo  all changes that have been made to the
                     current line.

              @@_c     macro expansion: execute the commands  found
                     in the alias __c.

FFIILLEESS
       ~/.profile
       /etc/profile
       /etc/suid_profile

BBUUGGSS
       Any  bugs  in pdksh should be reported to pdksh@cs.mun.ca.
       Please include the version  of  pdksh  (echo  $KSH_VERSION
       shows  it), the machine, operating system and compiler you
       are using and a description of how to repeat  the  bug  (a
       small  shell  script  that  demonstrates the bug is best).



                        November 28, 1994                      49





KSH(1)                    User commands                    KSH(1)


       The following, if relevant (if you  aren't  sure,  include
       them),  are  also  helpful:  options  you  are using (both
       options.h options and set -o options) and a copy  of  your
       config.h  (the  file  generated  by the configure script).
       New   versions   of   pdksh   can   be    obtained    from
       ftp.cs.mun.ca:pub/pdksh/.

AAUUTTHHOORRSS
       pdksh  is  based  on  the public domain 7th edition Bourne
       shell by Charles Forsyth and parts of  the  BRL  shell  by
       Doug  A. Gwyn, Doug Kingston, Ron Natalie, Arnold Robbins,
       Lou Salkind and others.  The first release  of  pdksh  was
       created  by Eric Gisin, and it was subsequently maintained
       by John R. MacMillan (chance!john@sq.sq.com), and Simon J.
       Gerraty  (sjg@zen.void.oz.au).   The current maintainer is
       Michael  Rendell  (michael@cs.mun.ca).   The  CONTRIBUTORS
       file  in  the source distribution contains a more complete
       list of people and their part in pdksh.

SSEEEE AALLSSOO
       awk(1),  sh(1),  csh(1),  ed(1),  getconf(1),   getopt(1),
       sed(1),  stty(1),  vi(1),  dup(2),  execve(2),  getgid(2),
       getuid(2), open(2), pipe(2), wait(2), getopt(3),  rand(3),
       signal(3), system(3), environ(5)

       _U_N_I_X  _S_h_e_l_l  _P_r_o_g_r_a_m_m_i_n_g_,  Stephen  G.  Kochan, Patrick H.
       Wood, Hayden.

       _T_h_e _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_,  Morris
       Bolsky and David Korn, 1989, ISBN 0-13-516972-0.



























                        November 28, 1994                      50


[ RETURN TO DIRECTORY ]