home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / SH164X.ZIP / SH.MAN < prev   
Text File  |  1991-03-01  |  45KB  |  1,028 lines

  1. This is the OS/2 version of the MS-DOS SH 1.6.2
  2.  
  3. Changes:
  4.  
  5. - background processes with & character, reporting of exit status of
  6.   ending bg processes and waiting for child processes on exit
  7.  
  8. - "jobs" command and jobs-key (default Ctrl-Tab) for list of actual
  9.   background processes
  10.  
  11. - real OS/2 pipes, except on `` commands
  12.  
  13. - increased length of expanded command line (2k, max. would be 32k)
  14.   instead of 127 bytes in DOS version
  15.  
  16. - #! in shell scripts works now correctly with, for example, gawk
  17.  
  18. - the "type" internal command of sh was changed to recognize
  19.   the internal commands of sh as well as CMD.EXE commands
  20.  
  21. - a fatal bug with commands in () ("sub-shell") was fixed
  22.  
  23.  
  24. Original DOS manual:
  25.  
  26. ------8<-------------------------8<------------------------------
  27. NAME
  28.      sh, rsh - shell, the standard/restricted command programming
  29.      language
  30.  
  31. SYNOPSIS
  32.      sh [ -acefhiknmrstuvx ] [ args ]
  33.      rsh [ -acefhiknmrstuvx ] [ args ]
  34.  
  35. DESCRIPTION
  36.      Sh is a command programming language that executes commands
  37.      read from a terminal or a file.  Rsh is a restricted version
  38.      of the standard command interpreter sh; it is used to set up
  39.      login names and execution environments whose capabilities
  40.      are more controlled than those of the standard shell.  See
  41.      Invocation below for the meaning of arguments to the shell.
  42.  
  43.      Definitions
  44.      A blank is a tab or a space.  A name is a sequence of
  45.      letters, digits, or underscores beginning with a letter or
  46.      underscore.  A parameter is a name, a digit, or any of the
  47.      characters *, @, #, ?, -, $, and !.
  48.  
  49.      Commands
  50.      A simple-command is a sequence of non-blank words separated
  51.      by blanks.  The first word specifies the name of the command
  52.      to be executed.  Except as specified below, the remaining
  53.      words are passed as arguments to the invoked command.  The
  54.      command name is passed as argument 0 (see exec(2)).  The
  55.      value of a simple-command is its exit status if it ter-
  56.      minates normally, or (octal) 200+status if it terminates
  57.      abnormally (see signal(2) for a list of status values).
  58.  
  59.      A pipeline is a sequence of one or more commands separated
  60.      by | (or, for historical compatibility, by ^).  The standard
  61.      output of each command but the last is connected by a
  62.      pipe(2) to the standard input of the next command.  Each
  63.      command is run as a separate process; the shell waits for
  64.      the last command to terminate.  The exit status of a pipe-
  65.      line is the exit status of the last command.
  66.  
  67.      A list is a sequence of one or more pipelines separated by
  68.      ;, &&, or ||, and optionally terminated by ;.  Of these
  69.      three symbols, ; has a lower precedence than that of && and
  70.      ||.  The symbols && and || also have equal precedence.  A
  71.      semicolon (;) causes sequential execution of the preceding
  72.      pipeline.  The symbol && (||) causes the list following it
  73.      to be executed only if the preceding pipeline returns a zero
  74.      (non-zero) exit status.  An arbitrary number of new-lines
  75.      may appear in a list, instead of semicolons, to delimit com-
  76.      mands.
  77.  
  78.      A command is either a simple-command or one of the follow-
  79.      ing.  Unless otherwise stated, the value returned by a com-
  80.      mand is that of the last simple-command executed in the com-
  81.      mand.
  82.  
  83.      for name [ in word ... ] do list done
  84.           Each time a for command is executed, name is set to the
  85.           next word taken from the in word list.  If in word ...
  86.           is omitted, then the for command executes the do list
  87.           once for each positional parameter that is set (see
  88.           Parameter Substitution below).  Execution ends when
  89.           there are no more words in the list.
  90.      case word in [ pattern [ | pattern ] ... ) list ;; ] ... esac
  91.           A case command executes the list associated with the
  92.           first pattern that matches word.  The form of the pat-
  93.           terns is the same as that used for file-name generation
  94.           (see File Name Generation) except that a slash, a lead-
  95.           ing dot, or a dot immediately following a slash need
  96.           not be matched explicitly, and the match is case sensi-
  97.           tive.
  98.      if list then list [ elif list then list ] ... [ else list ] fi
  99.           The list following if is executed and, if it returns a
  100.           zero exit status, the list following the first then is
  101.           executed.  Otherwise, the list following elif is exe-
  102.           cuted and, if its value is zero, the list following the
  103.           next then is executed.  Failing that, the else list is
  104.           executed.  If no else list or then list is executed,
  105.           then the if command returns a zero exit status.
  106.      while list do list done
  107.           A while command repeatedly executes the while list and,
  108.           if the exit status of the last command in the list is
  109.           zero, executes the do list; otherwise the loop ter-
  110.           minates.  If no commands in the do list are executed,
  111.           then the while command returns a zero exit status;
  112.           until may be used in place of while to negate the loop
  113.           termination test.
  114.      (list)
  115.           Execute list in a sub-shell.  The shell creates a new
  116.           environment in which to execute the list, but does not
  117.           fork a sub-shell as a Unix system would.  The original
  118.           environment is restored on completion.
  119.      {list;}
  120.           list is simply executed.
  121.      name () {list;}
  122.           Define a function which is referenced by name.  The
  123.           body of the function is the list of commands between {
  124.           and }.  Execution of functions is described below (see
  125.           Execution).
  126.  
  127.      The following words are only recognized as the first word of
  128.      a command and when not quoted:
  129.  
  130.      if then else elif fi case esac for while until do done { }
  131.  
  132.      Comments
  133.      A word beginning with # causes that word and all the follow-
  134.      ing characters up to a new-line to be ignored.
  135.  
  136.      Command Substitution
  137.      The standard output from a command enclosed in a pair of
  138.      grave accents (``) may be used as part or all of a word;
  139.      trailing new-lines are removed.
  140.  
  141.      Parameter Substitution
  142.      The character $ is used to introduce substitutable parame-
  143.      ters.  There are two types of parameters, positional and
  144.      keyword.  If parameter is a digit, it is a positional param-
  145.      eter.  Positional parameters may be assigned values by set.
  146.      Keyword parameters (also known as variables) may be assigned
  147.      values by writing:
  148.  
  149.           name = value [ name = value ] ...
  150.  
  151.      Pattern-matching is not performed on value.  There cannot be
  152.      a function and a variable with the same name.
  153.  
  154.      ${parameter}
  155.           The value, if any, of the parameter is substituted.
  156.           The braces are required only when parameter is followed
  157.           by a letter, digit, or underscore that is not to be
  158.           interpreted as part of its name.  If parameter is * or
  159.           @, all the positional parameters, starting with $1, are
  160.           substituted (separated by spaces).  Parameter $0 is set
  161.           from argument zero when the shell is invoked.
  162.      ${parameter:-word}
  163.           If parameter is set and is non-null, substitute its
  164.           value; otherwise substitute word.
  165.      ${parameter:=word}
  166.           If parameter is not set or is null set it to word; the
  167.           value of the parameter is substituted.  Positional
  168.           parameters may not be assigned to in this way.
  169.      ${parameter:?word}
  170.           If parameter is set and is non-null, substitute its
  171.           value; otherwise, print word and exit from the shell.
  172.           If word is omitted, the message ``parameter null or not
  173.           set'' is printed.
  174.      ${parameter:+word}
  175.           If parameter is set and is non-null, substitute word;
  176.           otherwise substitute nothing.
  177.  
  178.      In the above, word is not evaluated unless it is to be used
  179.      as the substituted string, so that, in the following exam-
  180.      ple, pwd is executed only if d is not set or is null:
  181.  
  182.           echo ${d:-`pwd`}
  183.  
  184.      If the colon (:) is omitted from the above expressions, the
  185.      shell only checks whether parameter is set or not (It is not
  186.      clear what this means).
  187.  
  188.      The following parameters are automatically set by the shell:
  189.           # The number of positional parameters in decimal.
  190.           - Flags supplied to the shell on invocation or by the
  191.             set command.
  192.           ? The decimal value returned by the last synchronously
  193.             executed command.
  194.           $ The process number of this shell.
  195.           ! The process number of the last background command
  196.             invoked.
  197.           ~ The shell reserves all variables beginning with a ~
  198.             for its own internal use and these variables cannot
  199.             be accessed by the user.
  200.  
  201.      The following parameters are used by the shell:
  202.           CDPATH
  203.             The search path for the cd command.  (Note that
  204.             becuase a colon is used by MSDOS to indicate a drive,
  205.             a semi-colon is used to separate the path names
  206.             instead of a colon - this implies that the CDPATH
  207.             variable must be set using single or double quotes to
  208.             surround the value).
  209.           EXTENDED_LINE
  210.             This parameter defines a file containing a list of
  211.             command which can accept an Extended Command Line
  212.             using the indirect command file character @.  When a
  213.             command which can process the Extended Command Line
  214.             finds a parameter starting with a @ in the command
  215.             list, treats the rest of the parameter as a file and
  216.             reads the parameters from that file.  Examples of
  217.             this functionality include the Standard Linker and
  218.             Librarian.  The filename defined by EXTENDED_LINE
  219.             contains a list of command (including the .exe or
  220.             .com extension) separated by a newlines.   If the
  221.             command is in upper case, the file name on the com-
  222.             mand line is set up with backslashes as the directory
  223.             separator.  Otherwise, slashes (Unix style) are used.
  224.             This functionality allows the user to get round the
  225.             127 byte command line length limit of MSDOS.
  226.           HISTFILE
  227.             The file where command history is saved across login
  228.             sessions.  The default value is $HOME/history.sh.
  229.           HOME
  230.             The default argument (home directory) for the cd com-
  231.             mand.
  232.           IFS
  233.             Internal field separators, normally space, tab, and
  234.             new-line.
  235.           MAIL
  236.             If this parameter is set to the name of a mail file
  237.             and the MAILPATH parameter is not set, the shell
  238.             informs the user of the arrival of mail in the speci-
  239.             fied file.
  240.           MAILCHECK
  241.             This parameter specifies how often (in seconds) the
  242.             shell will check for the arrival of mail in the files
  243.             specified by the MAILPATH or MAIL parameters.  If set
  244.             to 0, the shell will check before each prompt.
  245.           MAILPATH
  246.             A colon (:) separated list of file names.  If this
  247.             parameter is set, the shell informs the user of the
  248.             arrival of mail in any of the specified files. Each
  249.             file name can be followed by % and a message that
  250.             will be printed when the modification time changes.
  251.             The default message is "you have mail".
  252.           PATH
  253.             The search path for commands (see Execution below).
  254.             The user may not change PATH if executing under rsh.
  255.             (Note that because a colon is used by MSDOS to indi-
  256.             cate a drive, a semi-colon is used to separate the
  257.             path names instead of a colon - this implies that the
  258.             PATH variable must be set using single or double
  259.             quotes to surround the value).
  260.           PS1
  261.             Primary prompt string, by default ``$ ''.
  262.           PS2
  263.             Secondary prompt string, by default ``> ''.
  264.           SHELL
  265.             When the shell is invoked, it scans the environment
  266.             (see Environment below) for this name.  If it is
  267.             found and there is an 'r' in the file name part of
  268.             its value, the shell becomes a restricted shell.
  269.           TMP
  270.             The location of temporary files created by the shell.
  271.      The shell gives default values to PATH, PS1, PS2, SHELL,
  272.      HOME and IFS.
  273.      Blank Interpretation
  274.      After parameter and command substitution, the results of
  275.      substitution are scanned for internal field separator char-
  276.      acters (those found in IFS) and split into distinct argu-
  277.      ments where such characters are found.  Explicit null argu-
  278.      ments ("" or '') are retained.  Implicit null arguments
  279.      (those resulting from parameters that have no values) are
  280.      removed.
  281.      File Name Generation
  282.      Following substitution, each command word is scanned for the
  283.      characters *, ? and [.  If one of these characters appears
  284.      the word is regarded as a pattern.  The word is replaced
  285.      with alphabetically sorted file names that match the
  286.      pattern.  If no file name is found that matches the pattern,
  287.      the word is left unchanged.  The character . at the start of
  288.      a file name or immediately following a /, as well as the
  289.      character / itself, must be matched explicitly.  When match-
  290.      ing patterns for file names, the shell ignores the case of
  291.      the pattern and the file directory entries.  Generated file
  292.      names are always in lower case.
  293.           * Matches any string, including the null string.
  294.           ? Matches any single character.
  295.           [ ... ]
  296.             Matches any one of the enclosed characters.  A pair
  297.             of characters separated by - matches any character
  298.             lexically between the pair, inclusive.  If the first
  299.             character following the opening ``['' is a ``!'' any
  300.             character not enclosed is matched.
  301.  
  302.      Quoting
  303.      The following characters have a special meaning to the shell
  304.      and cause termination of a word unless quoted:
  305.  
  306.           ;  &  (  )  |  ^  <  >  new-line  space  tab
  307.  
  308.      A character may be quoted (i.e., made to stand for itself)
  309.      by preceding it with a \.  The pair \new-line is ignored.
  310.      All characters enclosed between a pair of single quote marks
  311.      (''), except a single quote, are quoted.  Inside double
  312.      quote marks (""), parameter and command substitution occurs
  313.      and \ quotes the characters \, `, ", and $. "$*" is
  314.      equivalent to "$1 $2 ...", whereas "$@" is equivalent to
  315.      "$1" "$2" ....
  316.  
  317.      Prompting
  318.      When used interactively, the shell prompts with the value of
  319.      PS1 before reading a command.  If at any time a new-line is
  320.      typed and further input is needed to complete a command, the
  321.      secondary prompt (i.e., the value of PS2) is issued.
  322.  
  323.      Many people like to have the shell provide them with useful
  324.      information in their prompt.  To accommodate this, the shell
  325.      recognises special sequences of characters in the values of
  326.      PS1 and PS2, and substitutes the appropriate information for
  327.      them.  The special sequences and what they signify are:
  328.  
  329.           %dPlace the current date, in the form DAY DD-MM-YY into
  330.             the prompt.
  331.  
  332.           %ePlace the current event number (as defined by the
  333.             history command) into the prompt.  If history evalua-
  334.             tion has been turned off (via history -d), no number
  335.             will be substituted in (i.e. the %e will be removed).
  336.  
  337.           %nPlace the current working drive into the prompt.
  338.  
  339.           %pPlace the current working directory into the prompt.
  340.  
  341.           %tPlace the current time of day, in the form HH:MM into
  342.             the prompt.  The time is on a 24 hour clock, i.e.
  343.             1:30 in the afternoon will be 13:30.
  344.  
  345.           %vPlace the MSDOS version number, in the form  MSDOS
  346.             MM:MM into the prompt.
  347.  
  348.           %%Place the character % into the prompt.
  349.  
  350.           \xxx
  351.             Place the character \xxx into the prompt.  The pro-
  352.             cessing of escape sequences is the same as that for
  353.             echo.
  354.  
  355.      Some of these facilities are of more use than others.
  356.  
  357.      Input/Output
  358.      Before a command is executed, its input and output may be
  359.      redirected using a special notation interpreted by the
  360.      shell.  The following may appear anywhere in a simple-
  361.      command or may precede or follow a command and are not
  362.      passed on to the invoked command; substitution occurs before
  363.      word or digit is used:
  364.  
  365.      <word         Use file word as standard input (file descrip-
  366.                    tor 0).
  367.      >word         Use file word as standard output (file
  368.                    descriptor 1).  If the file does not exist it
  369.                    is created; otherwise, it is truncated to zero
  370.                    length.
  371.      >>word        Use file word as standard output.  If the file
  372.                    exists output is appended to it (by first
  373.                    seeking to the end-of-file); otherwise, the
  374.                    file is created.
  375.      <<[-]word     The shell input is read up to a line that is
  376.                    the same as word, or to an end-of-file.  The
  377.                    resulting document becomes the standard input.
  378.                    If any character of word is quoted, no
  379.                    interpretation is placed upon the characters
  380.                    of the document; otherwise, parameter and com-
  381.                    mand substitution occurs, (unescaped) \new-
  382.                    line is ignored, and \ must be used to quote
  383.                    the characters \, $, `, and the first charac-
  384.                    ter of word.  If - is appended to <<, all
  385.                    leading tabs are stripped from word and from
  386.                    the document.
  387.      <&digit       Use the file associated with file descriptor
  388.                    digit as standard input.  Similarly for the
  389.                    standard output using >&digit.
  390.      <&-           The standard input is closed.  Similarly for
  391.                    the standard output using >&-.
  392.  
  393.      If any of the above is preceded by a digit, the file
  394.      descriptor which will be associated with the file is that
  395.      specified by the digit (instead of the default 0 or 1).  For
  396.      example:
  397.  
  398.           ... 2>&1
  399.  
  400.      associates file descriptor 2 with the file currently associ-
  401.      ated with file descriptor 1.
  402.  
  403.      The order in which redirections are specified is signifi-
  404.      cant.  The shell evaluates redirections left-to-right.  For
  405.      example:
  406.  
  407.           ... 1>xxx 2>&1
  408.  
  409.      first associates file descriptor 1 with file xxx.  It asso-
  410.      ciates file descriptor 2 with the file associated with file
  411.      descriptor 1 (i.e. xxx).  If the order of redirections were
  412.      reversed, file descriptor 2 would be associated with the
  413.      terminal (assuming file descriptor 1 had been) and file
  414.      descriptor 1 would be associated with file xxx .
  415.  
  416.      The environment for the execution of a command contains the
  417.      file descriptors of the invoking shell as modified by
  418.      input/output specifications.
  419.  
  420.      Redirection of output is not allowed in the restricted
  421.      shell.
  422.  
  423.      Environment
  424.      The environment (see environ(5)) is a list of name-value
  425.      pairs that is passed to an executed program in the same way
  426.      as a normal argument list.  The shell interacts with the
  427.      environment in several ways.  On invocation, the shell scans
  428.      the environment and creates a parameter for each name found,
  429.      giving it the corresponding value.  If the user modifies the
  430.      value of any of these parameters or creates new parameters,
  431.      none of these affects the environment unless the export com-
  432.      mand is used to bind the shell's parameter to the environ-
  433.      ment (see also set -a).  A parameter may be removed from the
  434.      environment with the unset command.  The environment seen by
  435.      any executed command is thus composed of any unmodified
  436.      name-value pairs originally inherited by the shell, minus
  437.      any pairs removed by unset, plus any modifications or addi-
  438.      tions, all of which must be noted in export commands.
  439.  
  440.      The environment for any simple-command may be augmented by
  441.      prefixing it with one or more assignments to parameters.
  442.      Thus:
  443.  
  444.           TERM=450 cmd args             and
  445.           (export TERM; TERM=450; cmd args)
  446.  
  447.      are equivalent (as far as the execution of cmd is con-
  448.      cerned).
  449.  
  450.      If the -k flag is set, all keyword arguments are placed in
  451.      the environment, even if they occur after the command name.
  452.      The following first prints a=b c and c:
  453.  
  454.           echo a=b c
  455.           set -k
  456.           echo a=b c
  457.  
  458.      Signals
  459.      The INTERRUPT and QUIT signals for an invoked command are
  460.      ignored if the command is followed by &; otherwise signals
  461.      have the values inherited by the shell from its parent, with
  462.      the exception of signal 11 (but see also the trap command
  463.      below).
  464.  
  465.      History
  466.      When reading input from an interactive terminal, a ``!'' at
  467.      the start of a line signals to the shell that it should
  468.      attempt to perform a history subsitution.  A history subsi-
  469.      tution is a short-hand method which allows the user to
  470.      recall a previous command for execution or editing.  The
  471.      recalled command is placed in the command line for editing
  472.      or passing to the rest of the shell for normal processing.
  473.      A history substitution takes the form:
  474.  
  475.           ! [ str | num ] terminator
  476.  
  477.      !num will place the history command with the specified
  478.      number in the command line.  !str will find the most recent
  479.      command line that started with the characters in str.
  480.  
  481.      The terminator determines what action is performed after the
  482.      history line has been found.  If the original history com-
  483.      mand is entered using the <return> key, the new command line
  484.      is passed directly to the shell.  If the <end> key is
  485.      pressed, the new command line can be edited in the manner
  486.      described below.
  487.  
  488.      Command Line Editing
  489.      When reading input from an interactive terminal, certain
  490.      keystrokes allow the current input line to be edited.  The
  491.      following keystrokes are available:
  492.  
  493.      Cursor Right
  494.           Move the cursor right one character
  495.  
  496.      Control-Cursor Right
  497.           Move the cursor right one word
  498.  
  499.      Cursor Left
  500.           Move the cursor left one character
  501.  
  502.      Control-Cursor Left
  503.           Move the cursor left one word
  504.  
  505.      Cursor Up
  506.           Get the previous command from the history file
  507.  
  508.      Cursor Down
  509.           Get the next command from the history file
  510.  
  511.      Insert
  512.           Toggle insert/overwrite mode
  513.  
  514.      Delete
  515.           Delete the current character
  516.  
  517.      Home Move the cursor to the start of the command
  518.  
  519.      End  Move the cursor to the end of the command, unless the
  520.           first character of the command is a !, in which case
  521.           the appropriate history search is done.
  522.  
  523.      Control-End
  524.           Delete to the end of the line
  525.  
  526.      Page-Up
  527.           Search backwards from the current history command for
  528.           the next match against the last history request.  This
  529.           command can only be used after End has been used to
  530.           select a history line.
  531.  
  532.      Page-Down
  533.           Search forewards from the current history command for
  534.           the next match against the last history request.  This
  535.           command can only be used after End has been used to
  536.           select a history line.
  537.  
  538.      Backspace
  539.           Move the cursor back one character, erasing the current
  540.           character.
  541.  
  542.      Return
  543.           Execute the command line, unless the first character of
  544.           the command is a !, in which case the appropriate his-
  545.           tory processing is done.
  546.  
  547.      Execution
  548.      Each time a command is executed, the above substitutions are
  549.      carried out.  If the command name matches one of the Special
  550.      Commands listed below, it is executed in the shell process.
  551.      If the command name does not match a Special Command, but
  552.      matches the name of a defined function, the function is exe-
  553.      cuted in the shell process (note how this differs from the
  554.      execution of shell procedures).  The positional parameters
  555.      $1, $2, ....  are set to the arguments of the function.  If
  556.      the command name matches neither a Special Command nor the
  557.      name of a defined function, a new process is created and an
  558.      attempt is made to execute the command via exec(2).
  559.  
  560.      The shell parameter PATH defines the search path for the
  561.      directory containing the command.  Alternative directory
  562.      names are separated by a semi-colon (;).  The default path
  563.      is ;c:/bin;c:/usr/bin (specifying the current directory,
  564.      c:/bin, and c:/usr/bin, in that order).  Note that the
  565.      current directory is specified by a null path name, which
  566.      can appear immediately after the equal sign or between the
  567.      semi-colon delimiters anywhere else in the path list.  If
  568.      the command name contains a / or starts with x: (where x is
  569.      a drive letter) the search path is not used; such commands
  570.      will not be executed by the restricted shell.  Otherwise,
  571.      each directory in the path is searched for an executable
  572.      file.
  573.  
  574.      If the file does not have a .com or .exe extension, it is
  575.      opened and the first 5 characters are read.  If the first 5
  576.      characters are the string #!sh\n it is assumed to be a file
  577.      containing shell commands.  Note that the shell will check
  578.      the file and if that file does not exist or is not a script,
  579.      it will try the file with an extension of .sh.  If a .sh
  580.      file is found, that will be processed.  A sub-shell is
  581.      spawned to read it.  A parenthesized command is also exe-
  582.      cuted in a sub-shell.
  583.  
  584.      Special Commands
  585.      Input/output redirection is permitted for these commands.
  586.      File descriptor 1 is the default output location.
  587.  
  588.      :    No effect; the command does nothing.  A zero exit code
  589.           is returned.
  590.  
  591.      letter:
  592.           Select the drive specified by letter.
  593.  
  594.      . file
  595.           Read and execute commands from file and return.  The
  596.           search path specified by PATH is used to find the
  597.           directory containing file.
  598.  
  599.      break [ n ]
  600.           Exit from the enclosing for or while loop, if any.  If
  601.           n is specified, break n levels.
  602.  
  603.      continue [ n ]
  604.           Resume the next iteration of the enclosing for or while
  605.           loop.  If n is specified, resume at the n-th enclosing
  606.           loop.
  607.  
  608.      cd [ arg ]
  609.           Change the current directory to arg.  The shell parame-
  610.           ter HOME is the default arg.  The shell parameter
  611.           CDPATH defines the search path for the directory con-
  612.           taining arg.  Alternative directory names are separated
  613.           by a semi-colon (;).  The default path is <null>
  614.           (specifying the current directory).  Note that the
  615.           current directory is specified by a null path name,
  616.           which can appear immediately after the equal sign or
  617.           between the semi-colon delimiters anywhere else in the
  618.           path list.  If arg begins with a / or x: (where x is a
  619.           drive letter), the search path is not used.  Otherwise,
  620.           each directory in the path is searched for arg.  The cd
  621.           command may not be executed by rsh.
  622.  
  623.      echo [ arg ... ]
  624.           Echo arguments. Echo writes its arguments separated by
  625.           blanks and terminated by a new-line on the standard
  626.           output.  It also understands C-like escape conventions;
  627.           beware of conflicts with the shell's use of \:
  628.           \bbackspace
  629.           \cprint line without new-line
  630.           \fform-feed
  631.           \nnew-line
  632.           \rcarriage return
  633.           \ttab
  634.           \vvertical tab
  635.           \\backslash
  636.           \nthe 8-bit character whose ASCII code is the 1-, 2- or
  637.             3-digit octal number n, which must start with a zero.
  638.  
  639.           Echo is useful for producing diagnostics in command
  640.           files and for sending known data into a pipe.
  641.  
  642.      eval [ arg ... ]
  643.           The arguments are read as input to the shell and the
  644.           resulting command(s) executed.
  645.  
  646.      exec [ arg ... ]
  647.           The command specified by the arguments is executed in
  648.           place of this shell without creating a new process.
  649.           Input/output arguments may appear and, if no other
  650.           arguments are given, cause the shell input/output to be
  651.           modified.
  652.  
  653.      exit [ n ]
  654.           Causes a shell to exit with the exit status specified
  655.           by n.  If n is omitted the exit status is that of the
  656.           last command executed (an end-of-file will also cause
  657.           the shell to exit.)
  658.  
  659.      export [ name ... ]
  660.           The given names are marked for automatic export to the
  661.           environment of subsequently-executed commands.  If no
  662.           arguments are given, a list of all names that are
  663.           exported in this shell is printed.  Function names may
  664.           not be exported.
  665.  
  666.      getopt optstring name [ args ... ]
  667.           Parse command options and write them to standard out-
  668.           put.  Getopt is used to break up options in command
  669.           lines for easy parsing by shell procedures and to check
  670.           for legal options.  Optstring is a string of recognized
  671.           option letters (see getopt(3C)); if a letter is fol-
  672.           lowed by a colon, the option is expected to have an
  673.           argument which may or may not be separated from it by
  674.           white space.  The special option -- is used to delimit
  675.           the end of the options.  If it is used explicitly,
  676.           getopt will recognize it; otherwise, getopt will gen-
  677.           erate it; in either case, getopt will place it at the
  678.           end of the options.  Each option is preceded by a - and
  679.           is in its own positional parameter; each option argu-
  680.           ment is also parsed into its own positional parameter.
  681.  
  682.           The following code fragment shows how one might process
  683.           the arguments for a command that can take the options a
  684.           or b, as well as the option o, which requires an argu-
  685.           ment:
  686.  
  687.           set -- `getopt abo: $*`
  688.           if [ $? != 0 ]
  689.           then
  690.                echo $USAGE
  691.                exit 2
  692.           fi
  693.           for i in $*
  694.           do
  695.                case $i in
  696.                -a | -b)  FLAG=$i; shift;;
  697.                -o)       OARG=$2; shift 2;;
  698.                --)       shift; break;;
  699.                esac
  700.           done
  701.  
  702.           This code will accept any of the following as
  703.           equivalent:
  704.  
  705.           cmd -aoarg file file
  706.           cmd -a -o arg file file
  707.           cmd -oarg -a file file
  708.           cmd -a -oarg -- file file
  709.  
  710.      history [ -dei ]
  711.           The history command, with no arguments, will print all
  712.           the commands that are currently saved in the shell's
  713.           history buffers.  As new commands are executed, and
  714.           space in the buffers runs out, old commands will be
  715.           deleted.  The history commands prints out the stored
  716.           commands with sequence numbers.  Negative numbered com-
  717.           mands, through command number zero, are commands that
  718.           were retrieved from the saved history file.  Commands
  719.           starting at one were entered during the current login
  720.           session.  If a saved command contains embedded new-
  721.           lines, these will be printed out as the sequence \n, so
  722.           that individual command stay on one line.
  723.  
  724.           The arguments changes the way the shell processes his-
  725.           tory information as follows:
  726.  
  727.           -dDisable the saving of commands in the history file.
  728.  
  729.           -eEnable the saving of commands in the history file.
  730.  
  731.           -iInitialise the history file.
  732.  
  733.      msdos [ name ... ]
  734.           The given names are marked msdos format and if the -m
  735.           flag is set, the values of the these names are exported
  736.           to child processes with the any slashes in the value
  737.           replaced by backslashes.
  738.  
  739.      pwd  Print the current working directory.
  740.  
  741.      read [ name ... ]
  742.           One line is read from the standard input and the first
  743.           word is assigned to the first name, the second word to
  744.           the second name, etc., with leftover words assigned to
  745.           the last name.  The return code is 0 unless an end-of-
  746.           file is encountered.
  747.  
  748.      readonly [ name ... ]
  749.           The given names are marked readonly and the values of
  750.           the these names may not be changed by subsequent
  751.           assignment.  If no arguments are given, a list of all
  752.           readonly names is printed.
  753.  
  754.      return [ n ]
  755.           Causes a function to exit with the return value speci-
  756.           fied by n.  If n is omitted, the return status is that
  757.           of the last command executed.
  758.  
  759.      set [ --aefkmntuvx [ arg ... ] ]
  760.  
  761.           -aMark variables which are modified or created for
  762.             export.
  763.  
  764.           -eExit immediately if a command exits with a non-zero
  765.             exit status.
  766.  
  767.           -fDisable file name generation
  768.  
  769.           -kAll keyword arguments are placed in the environment
  770.             for a command, not just those that precede the com-
  771.             mand name.
  772.  
  773.           -mFor those variables marked as msdos variables, the
  774.             values are exported to child processes with the
  775.             slashes replaced by backslashes.  Most MSDOS utili-
  776.             ties do not care if a file name contains a slash or
  777.             backslash as a directory separator.  However, some
  778.             like the linker require backslashes in the value of
  779.             the LIB variable.
  780.  
  781.           -nRead commands but do not execute them.
  782.  
  783.           -tExit after reading and executing one command.
  784.  
  785.           -uTreat unset variables as an error when substituting.
  786.  
  787.           -vPrint shell input lines as they are read.
  788.  
  789.           -xPrint commands and their arguments as they are exe-
  790.             cuted.
  791.  
  792.           --Do not change any of the flags; useful in setting $1
  793.             to -.
  794.  
  795.           Using + rather than - causes these flags to be turned
  796.           off.  These flags can also be used upon invocation of
  797.           the shell.  The current set of flags may be found in
  798.           $-.  The remaining arguments are positional parameters
  799.           and are assigned, in order, to $1, $2, ....  If no
  800.           arguments are given the values of all names are
  801.           printed.
  802.  
  803.      shift [ n ]
  804.           The positional parameters from $n+1 ...  are renamed $1
  805.           ....  If n is not given, it is assumed to be 1.
  806.  
  807.      swap [ options ]
  808.           This command defines how the shell will handle swap-
  809.           ping.  The options are
  810.  
  811.           off
  812.             Disable swapping.  The shell remains in memory whilst
  813.             the child is running and reduces the available memory
  814.             by about 200K (depending on the size of the environ-
  815.             ment and history).
  816.  
  817.           onEnable all devices.  The shell will swap out to
  818.             either expanded or extended memory or to disk, exe-
  819.             cute the command and then swap back in.  Whilest
  820.             swapped, the shell reduces the available memory by
  821.             about 3K.
  822.  
  823.           expand
  824.             Enable swapping to Expanded Memory.  The EMS drive
  825.             must exist on your system for this to work.
  826.  
  827.           extent [ start address ]
  828.             Enable swapping to Extended Memory.  The optional
  829.             start address defines the based address in the
  830.             Extended Memory at which point the shell writes its
  831.             swap area.  The default location is 0x100000.
  832.  
  833.           disk
  834.             Enable swapping to disk.  The shell creates a tem-
  835.             porary file and saves itself in it.  On completion,
  836.             the file is deleted.  This is the slowest method of
  837.             swapping.
  838.  
  839.           With no options, the current swapping options are
  840.           displayed.
  841.  
  842.      test expr or [ expr ]
  843.           Evaluate conditional expressions.  Test evaluates the
  844.           expression expr and, if its value is true, returns a
  845.           zero (true) exit status; otherwise, a non-zero (false)
  846.           exit status is returned; test also returns a non-zero
  847.           exit status if there are no arguments.  The following
  848.           primitives are used to construct expr:
  849.  
  850.           -r file     true if file exists and is readable.
  851.  
  852.           -w file     true if file exists and is writable.
  853.  
  854.           -x file     true if file exists and is executable.
  855.  
  856.           -f file     true if file exists and is a regular file.
  857.  
  858.           -d file     true if file exists and is a directory.
  859.  
  860.           -c file     true if file exists and is a character spe-
  861.                       cial file.
  862.  
  863.           -b file     true if file exists and is a block special
  864.                       file.
  865.  
  866.           -s file     true if file exists and has a size greater
  867.                       than zero.
  868.  
  869.           -t [ fildes ]
  870.                       true if the open file whose file descriptor
  871.                       number is fildes (1 by default) is associ-
  872.                       ated with a terminal device.
  873.  
  874.           -n s1       true if the length of the string s1 is
  875.                       zero.
  876.  
  877.           -n s1       true if the length of the string s1 is
  878.                       non-zero.
  879.  
  880.           s1 = s2     true if strings s1 and s2 are identical.
  881.  
  882.           s1 != s2    true if strings s1 and s2 are not identi-
  883.                       cal.
  884.  
  885.           s1          true if s1 is not the null string.
  886.  
  887.           n1 -eq n2   true if the integers n1 and n2 are algebra-
  888.                       ically equal.  Any of the comparisons -ne,
  889.                       -gt, -ge, -lt, and -le may be used in place
  890.                       of R-eq.
  891.  
  892.           These primaries may be combined with the following
  893.           operators:
  894.  
  895.           !           unary negation operator.
  896.  
  897.           -a          binary and operator.
  898.  
  899.           -o          binary or operator (-a has higher pre-
  900.                       cedence than -o).
  901.  
  902.           ( expr )    parentheses for grouping.
  903.  
  904.           Notice that all the operators and flags are separate
  905.           arguments to test.  Notice also that parentheses are
  906.           meaningful to the shell and, therefore, must be
  907.           escaped.
  908.  
  909.      trap [ arg ] [ n ] ...
  910.           The command arg is to be read and executed when the
  911.           shell receives signal(s) n.  (Note that arg is scanned
  912.           once when the trap is set and once when the trap is
  913.           taken.) Trap commands are executed in order of signal
  914.           number.  Any attempt to set a trap on a signal that was
  915.           ignored on entry to the current shell is ineffective.
  916.           An attempt to trap on signal 11 (memory fault) produces
  917.           an error.  If arg is absent all trap(s) n are reset to
  918.           their original values.  If arg is the null string this
  919.           signal is ignored by the shell and by the commands it
  920.           invokes.  If n is 0 the command arg is executed on exit
  921.           from the shell.  The trap command with no arguments
  922.           prints a list of commands associated with each signal
  923.           number.
  924.  
  925.      type [ name ... ]
  926.           For each name, indicate how it would be interpreted if
  927.           used as a command name.
  928.  
  929.      umask [ nnn ]
  930.           The user file-creation mask is set to nnn (see
  931.           umask(2)).  If nnn is omitted, the current value of the
  932.           mask is printed.
  933.  
  934.      unset [ name ... ]
  935.           For each name, remove the corresponding variable or
  936.           function.  The variables PATH, PS1, PS2, and IFS cannot
  937.           be unset.
  938.  
  939.      ver  Display the current version of the shell.
  940.  
  941.      Invocation
  942.      If the shell is invoked through exec(2) and the first char-
  943.      acter of argument zero is - or the -0(zero) switch is in the
  944.      invokation line, commands are initially read from
  945.      /etc/profile.sh and from $HOME/profile.sh, if such files
  946.      exist.  Thereafter, commands are read as described below,
  947.      which is also the case when the shell is invoked as /bin/sh.
  948.      The flags below are interpreted by the shell on invocation
  949.      only; Note that unless the -c or -s flag is specified, the
  950.      first argument is assumed to be the name of a file contain-
  951.      ing commands, and the remaining arguments are passed as
  952.      positional parameters to that command file:
  953.  
  954.      -c string If the -c flag is present commands are read from
  955.                string.
  956.      -s        If the -s flag is present or if no arguments
  957.                remain commands are read from the standard input.
  958.                Any remaining arguments specify the positional
  959.                parameters.  Shell output (except for Special Com-
  960.                mands) is written to file descriptor 2.
  961.      -i        If the -i flag is present or if the shell input
  962.                and output are attached to a terminal, this shell
  963.                is interactive.  In this case, the TERMINATE sig-
  964.                nal is ignored and the INTERRUPT signal is caught
  965.                and ignored.  In all cases, the QUIT signal is
  966.                ignored by the shell.
  967.      -r        If the -r flag is present, the shell is a res-
  968.                tricted shell.
  969.      -0(zero)  If the -0(zero) flag is present, this has the same
  970.                effect as starting the shell with the first char-
  971.                acter of argument zero as a - (see above).
  972.  
  973.      The remaining flags and arguments are described under the
  974.      set command above.
  975.  
  976.      Rsh Only
  977.      Rsh is used to set up login names and execution environments
  978.      whose capabilities are more controlled than those of the
  979.      standard shell.  The actions of rsh are identical to those
  980.      of sh, except that the following are disallowed:
  981.           changing directory (see cd(1)),
  982.           setting the value of $PATH
  983.           specifying path or command names containing /,
  984.           redirecting output (> and >>).
  985.  
  986.      The restrictions above are enforced after profile.sh is
  987.      interpreted.
  988.  
  989.      When a command to be executed is found to be a shell pro-
  990.      cedure, rsh invokes sh to execute it.  Thus, it is possible
  991.      to provide to the end-user shell procedures that have access
  992.      to the full power of the standard shell, while imposing a
  993.      limited menu of commands; this scheme assumes that the end-
  994.      user does not have write and execute permissions in the same
  995.      directory.
  996.  
  997.      The net effect of these rules is that the writer of the
  998.      profile.sh has complete control over user actions, by per-
  999.      forming guaranteed setup actions and leaving the user in an
  1000.      appropriate directory (probably not the login directory).
  1001.  
  1002.      The system administrator often sets up a directory of com-
  1003.      mands (i.e., /usr/rbin) that can be safely invoked by rsh.
  1004.      Some systems also provide a restricted editor red.
  1005.  
  1006. EXIT STATUS
  1007.      Errors detected by the shell, such as syntax errors, cause
  1008.      the shell to return a non-zero exit status.  If the shell is
  1009.      being used non-interactively execution of the shell file is
  1010.      abandoned.  Otherwise, the shell returns the exit status of
  1011.      the last command executed (see also the exit command above).
  1012.  
  1013. FILES
  1014.      /etc/profile.sh
  1015.      $HOME/profile.sh
  1016.      $TMP/sh*
  1017.  
  1018. LIMIITATIONS
  1019.      Any TSR (Terminate Stay Resident) programs must be loaded
  1020.      before loading Sh as the shell will overwrite the TSR when
  1021.      it reloads itself after swapping out.
  1022.  
  1023. SEE ALSO
  1024.      cd(1), env(1), test(1), umask(1).
  1025.      dup(2), exec(2), pipe(2), signal(2), umask(2), wait(2), pro-
  1026.      file(4), environ(5) in the UNIX System Programmer Reference
  1027.      Manual.
  1028.