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