home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d811 / bsh.lha / bsh / bsh.doc < prev    next >
Text File  |  1993-02-14  |  87KB  |  2,301 lines

  1.  
  2.                         CONTENTS
  3.  
  4.  
  5.         (0)     Features
  6.         (1)     Command pre-processor (parser)
  7.         (2)     Command-line editing
  8.         (3)     Command-list
  9.         (4)     Variables
  10.         (5)     Expressions
  11.         (6)     Redirection and pipes
  12.         (7)     Programming
  13.         (8)     Directory aliases
  14.         (9)     Problems
  15.  
  16.  
  17.     Bsh is an enhanced shell and interpretive programming language.  It
  18.     contains many advanced features not previously seen in shells on
  19.     the Amiga(TM) computer.  Bsh has been tested on an Amiga 3000
  20.     running AmigaDOS1.3, AmigaDOS2.04 and AmigaDOS2.1, on an Amiga
  21.     1000 running AmigaDOS1.2 and AmigaDOS1.3, and on an Amiga 500
  22.     running AmigaDOS2.04.
  23.  
  24.  
  25.                         MAJOR FEATURES
  26.  
  27.    o Command history.  Bsh remembers commands that you typed in a
  28.      history buffer; you can subsequently recall (and modify) these
  29.      commands using the command-line editing features described in
  30.      chapter 2.
  31.    o Command line editing (see chap. 2)
  32.    o Command substitution.  This allows you to place the output of one
  33.      command in the command-line of another.  See the IFS variable in
  34.      chapter 4.
  35.    o Redirection and piping (see chap. 6)
  36.    o Concurrent piping for external commands
  37.    o Here documents
  38.    o Command aliases
  39.    o File name completion using wildcards ('*', '?')
  40.    o Pattern permutations ({str1,str2}{str3,str4}...).  Each possible
  41.      permutation becomes a separate argument for the command.  For
  42.      example, to rename MyFunkyOldSourceFile.bak to
  43.      MyFunkyOldSourceFile.c:
  44.         % mv MyFunkyOldSourceFile.{bak,c}
  45.      This is not a wild-card operation, but it can be combined with
  46.      regular wildcards.  For example, to remove all files ending in
  47.      .bak or .o:
  48.         % rm *.{bak,o}
  49.    o Variables, array variables and environment variables (see chap. 4)
  50.    o Expression evaluation using constants, bsh variables, arithmetic
  51.      operators and functions (see chap. 5)
  52.    o bsh scripts
  53.    o Conditionals (IF, ELSEIF, ELSE, ENDIF)
  54.    o Looping (WHILE, ENDWHILE, CONTINUE, BREAK, GOTO)
  55.    o More than 50 builtin commands (see chap. 3)
  56.    o More than 40 builtin functions (see chap. 5)
  57.    o Command search by CLI path and by bsh path variable
  58.    o Directory aliases (see chap. 8).  Short abbreviations for the
  59.      current dirctory the parent of the current dirctory and the home
  60.      directory which can save lots of typing
  61.  
  62.  
  63.                         New features in bsh 0.95
  64.  
  65.    o Bsh is separated into a shared library containing most of the
  66.      code, and a very small command which just opens the library and
  67.      calls the main() entry point in it.  This allows multiple shells
  68.      to be running without multiple copies of the code segment in
  69.      memory at a time.
  70.  
  71.  
  72.                         New features in bsh 0.96
  73.  
  74.    o Command hashing.  When bsh finds a command in your search-path,
  75.      it remembers the location so that the next time you use the
  76.      command, it loads the command from the remembered location instead
  77.      of searching the path again.  This can significantly reduce the
  78.      number of disk accesses depending on the number of directories in
  79.      your search path.  The hash list can be manipulated using the HASH,
  80.      UNHASH, REHASH commands.
  81.    o Separate command newbsh creates a new shell in its own console
  82.      window.
  83.  
  84.  
  85.                         New features in bsh 0.97
  86.  
  87.    o Resident command loading.  Allows pure, and pseudo-pure (linked
  88.      with LATTICE cres.o) commands to be made resident.
  89.    o Redirection of standard error file.  Stderr redirection of external
  90.      (disk-based) commands requires AmigaDOS 2.0 to work.
  91.    o Bsh has been recompiled with Manx 5.0d using prototyping.
  92.    o WorkBench startup via newbsh (a tool icon is provided).  Newbsh
  93.      can also be started by clicking on a script icon.
  94.  
  95.  
  96.                         New features in bsh 0.98
  97.  
  98.    o Variable exporting, bsh variables can be EXPORTed to sub-shells.
  99.    o Window manipulations with the window command.
  100.    o Bsh and newbsh have been made RESIDENTable.
  101.    o Bsh has been recompiled with Manx 5.2a.
  102.  
  103.  
  104.                         New features to be included in bsh 1.0
  105.  
  106.    o Command grouping.  Commands may be grouped by placing a list of
  107.      commands within parentheses which may also contain a pipeline.
  108.      Also it is now possible to run a single command or command group
  109.      in the background or pipe the output of a group of commands into
  110.      another command.
  111.         % cmd &              run command cmd in the background
  112.         % cmd1 & cmd2        run cmd1 in the background while running
  113.                              cmd2
  114.         % (cmd1;cmd2) | cmd3 pipe output from group to input of cmd3
  115.      Command groups, and background commands are run in a separate
  116.      shell (bsh must be in your search path).  This feature also allows
  117.      concurrent piping of script programs - they are run in a separate
  118.      shell.
  119.      The command-grouping feature is not included in version 0.98.
  120.      This will be included with bsh 1.0.
  121.    o User definable functions (really resident scripts).
  122.    o A match() function which will compare a string with a pattern and
  123.      return true if the string matches the pattern.
  124.    o Some simple form of job control (at least the ability to stop
  125.      runaway or catatonic programs and recover the use of the shell).
  126.  
  127.  
  128.                         In the future...
  129.  
  130.      Also in the planning stage, an AppWindow feature which would
  131.      allow scripts to be run by just dropping their icons into a
  132.      bsh AppWindow, and an ARexx port.
  133.    1-0                     THE COMMAND LINE
  134.  
  135.     Before passing a command line on to a program, bsh performs an initial
  136.     editing (parsing) pass. First any history substitution is performed.
  137.     Next, if the command line contains multiple commands or command groups,
  138.     each is extracted and treated as a separate command line.  Then alias
  139.     and variable substitution is performed. Next, wildcard expansion is
  140.     performed with each matching file found occupying one argument position
  141.     on the command line.  Finally, redirection files are opened, and the
  142.     redirection operators ( <, > ) and redirection file names are removed
  143.     from the command line: the program being run never sees them.  Any of
  144.     the special characters recognized by the command parser can of course
  145.     be protected from their normal interpretation by quoting them.
  146.  
  147.  
  148.  
  149.     1-1                     HISTORY REPLACEMENT
  150.  
  151.     See also the HISTORY command in chapter 3.
  152.  
  153.     !!      At the beginning of a line, causes the previous
  154.             command to be re-executed.
  155.  
  156.     !string Causes the most recently entered command starting with
  157.             string to be re-executed.  See the HISTORY command.
  158.  
  159.     !n      Causes the nth command to be re-executed.
  160.  
  161.     !-n     Causes the n+1th previous command to be re-executed.
  162.             Using this, you can toggle repeatedly between two
  163.             commands:
  164.                 % cmd1
  165.                 % cmd2
  166.                 % !-1           re-executes cmd1
  167.                 % !-1           re-executes cmd2
  168.             To make things even easier, you could assign the string
  169.             "!-1\r" to the variable f2, and then just keep poking
  170.             the f2 function key until done.
  171.  
  172.  
  173.     1-2                         SEPARATORS
  174.  
  175.     ' '     A space; used as an argument separator.  In order to
  176.             include a space within an argument, you must quote it
  177.             (see below).
  178.  
  179.     ;       Is used as a command separator.
  180.  
  181.                 % cd foo ; ls
  182.  
  183.     #       Enter a comment.  The rest of the line is ignored if it
  184.             is immediately followed by a tab or space.
  185.  
  186.                 % foo bar # this command does something
  187.  
  188.     |       The pipe operator (see below under redirection).
  189.  
  190.     &       Is used as a command separator.  The command on the left
  191.             is run in the background; the command to the right is then
  192.             run without waiting for the first command to complete.
  193.             This requires the command grouping feature, not included in
  194.             version 0.98 of bsh.  You can also run a single command in
  195.             the background by appending an & to the command.
  196.  
  197.                 % foo & bar     Start foo in the background, then
  198.                                 run bar without waiting for foo.
  199.                 % foo &         Start foo in the background, bsh
  200.                                 returns to the prompt immediately.
  201.  
  202.  
  203.     (cmd...) Run a group of commands in a separate shell.  This requires
  204.             the command grouping feature, not included in version 0.98
  205.             of bsh.
  206.  
  207.  
  208.     1-3                         QUOTING
  209.  
  210.     'string'
  211.     "string" a quoted string.  For example, to set a variable to a string
  212.             containing spaces:
  213.  
  214.                 % set a "b     c"
  215.                 % echo $a
  216.                 b     c
  217.                 % set a b     c
  218.                 % echo $a
  219.                 b c
  220.  
  221.             Within double quotes, variables are still substituted but not
  222.             within single quotes.  Command substitution (`cmd`) also still
  223.             occurs within double quotes but not within single quotes.
  224.  
  225.                 % echo '$a'
  226.                 $a
  227.                 % echo "$a"
  228.                 b c
  229.  
  230.     \c      Protects a special character from normal interpretation;
  231.             \* is an asterisk rather than all the files in the current
  232.             directory.  To enter a backslash, just type "\\".  This is
  233.             also used to prevent alias substitution for a command.
  234.             Within double quotes, the backslash can also be used to enter
  235.             escape characters as follows:
  236.                 \a      a bell - ^G (control-G)
  237.                 \b      a backspace (control-H)
  238.                 \e      an escape (control-[)
  239.                 \f      a form feed (control-L)
  240.                 \n      a newline character (control-J)
  241.                 \r      a carriage return (control-M)
  242.                 \t      a tab (control-I)
  243.                 \nnn    one to three octal digits representing an ascii
  244.                         character of that value.
  245.  
  246.     `cmd`   Command substitution - execute command cmd and place its
  247.             output on the command line.  Each word of output from cmd
  248.             is a  separate argument for the command.  Words are delimited
  249.             according to the characters in the IFS variable (see chap. 4).
  250.             If IFS is undefined, words are delimited by space, tab, or
  251.             a newline.  This is a way for one command's output to become
  252.             anothers arguments.  For example, add all files in the current
  253.             directory and all subdirectories to the zoo archive foo.zoo.
  254.  
  255.                 % zoo a foo.zoo `find . -type f -print`
  256.  
  257.             You could even be a little more selective about it by piping
  258.             the output of find through pick:
  259.  
  260.                 % zoo a foo.zoo `find . -type f -print | pick`
  261.  
  262.             If the variable IFS has been defined, it contains a list of
  263.             the characters used to delimit words.  If you use 'find' to
  264.             generate a list of filenames, and the names might contain
  265.             spaces or tabs, you set IFS:
  266.  
  267.                 set IFS "\n"
  268.  
  269.             and each line of output from 'find' is treated as one word.
  270.  
  271.             Command substitution occurs within double quotes, but not
  272.             within single quotes.
  273.  
  274.  
  275.     1-4                 REDIRECTION OPERATORS
  276.  
  277.     See also chapter 6 for more information on redirection and pipes.
  278.  
  279.     >file   Redirect output from command.  Output from the command is
  280.             directed to the named file.
  281.     >>file  append output to end of the named file.
  282.  
  283.     2>file  Redirect standard error.  Redirection of standard error
  284.             for external (disk based) commands requires AmigaDOS
  285.             version 2.0, and cooperative utilities to work.
  286.     2>>file append error file.
  287.  
  288.     <file   redirect standard input.  The command takes input from the
  289.             named file rather than the console.
  290.  
  291.     <<string here-document: lines following this line in a script file
  292.             until a line beginning with <string> are read as
  293.             standard-input by the command.
  294.  
  295.     |       Is the pipe operator (also a command separator).  The
  296.             output from the first command becomes the input to the
  297.             second command.  See chapter 6 for more info on pipes.
  298.             You can string out several commands this way, forming a
  299.             "pipeline", each command after the first takes its input
  300.             from the output of the previous command.  Each command
  301.             except the last is considered a pipe-feeder.
  302.  
  303.                 % cmd1 | cmd2   Standard-output of cmd1 is
  304.                                 connected (piped) to standard-
  305.                                 input of cmd2.
  306.  
  307.     Redirection operators are not recognized within quotes.
  308.  
  309.  
  310.     1-5                 VARIABLE SUBSTITUTION
  311.  
  312.     See also chapter 4 for more information on variables, special
  313.     variables, and special variable forms.
  314.  
  315.     $name   If name is the name of a bsh variable, its value is
  316.             substituted for the $name occurrence.  If it is not a bsh
  317.             variable, the null string is substituted.
  318.                 % set a Fred
  319.                 % echo Hi, $a
  320.                 Hi, Fred
  321.  
  322.     ${name}x Concatenates a string on to the end of a variable. This
  323.             is so bsh can tell where the variable name ends and the
  324.             string begins as in the following example.
  325.                 % set a Mon
  326.                 % echo ${a}day
  327.                 Monday
  328.  
  329.     $array[$i]  Substitutes the i-th element of array if it exists.
  330.             If it does not exist, no changes are made.
  331.                 % set a Bob Bill Joe
  332.                 % set i 2
  333.                 % echo Hi, $a[1]
  334.                 Hi, Bill
  335.                 % echo Hi, $a[$i]
  336.                 Hi, Joe
  337.  
  338.     $#array Substitutes the number of elements in an array.  A zero
  339.             is substituted  if the variable is not defined or is not
  340.             an array.
  341.  
  342.     $?name  Substitutes 1 if name is defined, else 0.
  343.  
  344.     Variable substitution occurs within double quotes, but not within
  345.     single quotes.
  346.  
  347.  
  348.     1-6              FILENAME COMPLETION (WILDCARDS)
  349.  
  350.     *       Matches any string of characters of any length including
  351.             the null string.
  352.  
  353.                 % set a *       # creates an array a, containing the
  354.                                 # names of all files in the current dir
  355.  
  356.     ?       Matches any single character.
  357.  
  358.                 % echo ???      # echos the names of all files in the
  359.                                 # current dir whose names are  three
  360.                                 # characters long.
  361.  
  362.     {s1,s2} Matches either s1 or s2.  These are not wildcards in them-
  363.             selves, but expand as though they had matched.  If combined
  364.             with wildcards, only file names matching are expanded.
  365.             For example:
  366.  
  367.                 % echo {a,b,c}  # even if these don't match any files.
  368.                 a b c
  369.                 % echo *.{c,o}  # only matches existing files ending in
  370.                                 # in .c or .o
  371.  
  372.             This can be used with the SET command to construct arrays:
  373.  
  374.                 % set a {0,1}{0,1,2,3,4,5,6,7,8,9} # generates an array
  375.                                 # of 20 elements containing 00 thru 19
  376.  
  377.     Filename completion does not occur within quotes.
  378.  
  379.  
  380.     1-7                 DIRECTORY ALIASES
  381.  
  382.     See also chapter 8 for more information on directory aliases
  383.  
  384.     .       the current directory.
  385.     ..      the parent directory of the current dir.
  386.     ./f     the file 'f' in the current directory.
  387.     ../f    the file 'f' in the parent of the current dir.
  388.     ~       the home dir (specified by the home variable).
  389.     ~/f     the file 'f' in the home directory.
  390.  
  391.     Directory aliasing does not occur within quotes.
  392.    2-0                 COMMAND LINE EDITING
  393.  
  394.     Command-line editing is in effect from the time bsh prints the
  395.     prompt until you press <cr> unless bsh was invoked with the -a
  396.     option.  The command line can be up to 255 chars in length,
  397.     including the prompt; once the command-line has reached its
  398.     maximum length, attempts to insert a character are ignored.  Bsh
  399.     will normally keep track of the line width if the window is
  400.     resized or the font size is changed.
  401.  
  402.  
  403.     2-1                 CONTROL KEY DEFINITIONS
  404.  
  405.     Control keys cause the command-line editor to take certain actions
  406.     immediately.  Control keys not in the following list are ignored.
  407.  
  408.         ^A      Toggles insert/overtype mode
  409.         ^B      Moves the cursor backward one word (same as shift
  410.                 left-arrow)
  411.         ^\      EOF - this causes bsh to quit (unless _ignoreeof
  412.                 has been set)
  413.         ^E      Places the cursor at the end of the line
  414.         ^F      Moves the cursor forward one word (same as shift
  415.                 right-arrow)
  416.         ^H      Deletes the character to the left of the cursor
  417.         ^K      Deletes from the cursor to the end of the line
  418.         ^R      Retypes the current line
  419.         ^U      Deletes the portion of the line to the left of
  420.                 the cursor
  421.         ^W      Deletes from the cursor to the end of the word
  422.         ^X      Deletes the entire line
  423.         ^Z      Places the cursor at the beginning of the line
  424.                 following the prompt
  425.         ^-      Recalls the save-buffer.
  426.         del     Deletes the character under the cursor
  427.  
  428.  
  429.     2-2                 FUNCTION KEYS
  430.  
  431.         f1-f10  Function keys and their associated bsh variable names
  432.         s1-s10  Shifted Function keys and their associated variables
  433.         Help    Help key
  434.  
  435.     When you press a function key, if the corresponding variable is
  436.     defined, its contents are read just as though you had typed each
  437.     character of the variable.  If the variable is a command, you can
  438.     then execute it just by pressing <cr>, or continue to add to the
  439.     command line.  If the variable ends with a return (^M), the
  440.     command will be executed immediately without waiting for you to
  441.     press <cr>. The help key invokes the HELP command and then
  442.     reprints the command line as it was.
  443.  
  444.  
  445.     2-3                 THE ARROW KEYS
  446.  
  447.         Up arrow                Recall previous commands
  448.         Down arrow              Recall subsequent commands
  449.         Left arrow              Move the cursor backward on the
  450.                                 command line
  451.         Right arrow             Move the cursor forward on the
  452.                                 command line
  453.         Shift up arrow          Partial history recall
  454.         Shift down arrow        Partial history recall
  455.         Shift left arrow        Move the cursor to the beginning of
  456.                                 the previous word
  457.         Shift right arrow       Move the cursor to the beginning of
  458.                                 the next word
  459.  
  460.     If you type a partial command string, and then a shift up arrow,
  461.     bsh will search backward for a command beginning with that string;
  462.     if one is found, it replaces the current contents of the command
  463.     line.  Subsequent shift up/down arrows recall previous/subsequent
  464.     matching commands respectively.  If you alter the line, it becomes
  465.     the new search string; the search string is discarded when you
  466.     execute the command.
  467.  
  468.     Before searching the command history, bsh saves the current
  469.     command line in a save buffer; thus if you type an arrow key by
  470.     mistake, you can recover the line you were typing by entering a
  471.     ^- (control-minus).
  472.    3-0                         COMMANDS
  473.  
  474.  
  475.     The usual form of the command line is:
  476.         NAME [<input-file] [>output-file] [arguments]
  477.     where NAME is the command-name; for some commands (@, CD)
  478.     it is usually possible to omit the command name.  The redirection
  479.     arguments can appear anywhere in the command (even before the
  480.     command-name); this is in fact the only way to redirect the output
  481.     of the EVAL command.  However the pipe operator, if used must be
  482.     last, since it also serves as a command separator.  The order of
  483.     search is first aliases, then builtin commands, then resident
  484.     (RES/REZ/RESIDENT) commands, followed by directories specified in
  485.     the path variable.  For all builtin commands, case is significant;
  486.     they are all in lower case: Break is the DOS Break command, while
  487.     break is the builtin break command.  During the command search,
  488.     scripts are treated no differently than other commands; if a script
  489.     is found in your path and it has its script bit set, it is SOURCE'd,
  490.     and any specified arguments are placed in the argv array.
  491.  
  492.  
  493.  
  494.     3-1                     BUILTIN COMMANDS
  495.  
  496.  
  497.                                 ABORT
  498.       ABORT [exit-code [error-number]]
  499.  
  500.       Causes the remainder of the command line to be discarded.  Used
  501.       with exception processing (see chapter 7).  ABORT will also set
  502.       the exit-code and error-number if these are passed; this can be
  503.       used to restore the values which are normally cleared after each
  504.       command.
  505.  
  506.       % echo a;abort;echo b
  507.       a
  508.  
  509.  
  510.                                 ALIAS
  511.       ALIAS
  512.       ALIAS name
  513.       ALIAS name command...
  514.  
  515.       Declares name to be an alias for the command(s) specified.  In
  516.       order to specify more than one command, you must use quotes
  517.       around the entire list of commands.
  518.  
  519.       % alias frog "echo hop hop; echo hop; echo hop hop hop"
  520.  
  521.       then you can just type 'frog'.  All arguments to the alias are
  522.       placed in the variable '!' which you can reference anywhere in
  523.       the alias string:
  524.  
  525.       % alias rdonly protect $! -wd
  526.       % alias inc @ $!++
  527.  
  528.       % rdonly *.c
  529.       % i=0
  530.       % inc i
  531.       % echo i = $i
  532.       i = 1
  533.  
  534.       Additionally, you can use aliases to change the default options
  535.       for commands:
  536.  
  537.       % alias rm rm -i
  538.       % alias ls ls -l
  539.  
  540.       Henceforth every time you use the rm command, it will prompt for
  541.       each file before deleting it; ls will now give the long listing
  542.       by default.  Bsh detects the recurrence of the command and
  543.       prevents the alias from becoming recursive.
  544.  
  545.       If an alias has the same name as a normal command, you can still
  546.       use the normal command by preceding the command with a backslash.
  547.  
  548.       % \rm *.info      # remove .info files without prompting
  549.       % \ls             # print the short file listing
  550.  
  551.       See also UNALIAS
  552.  
  553.  
  554.                                 ARRAY
  555.       ARRAY varname[size] ...
  556.       ARRAY varname ...
  557.  
  558.       Declares varname to be an array of size elements.  If varname
  559.       already exists, its contents are lost.  When the array is created,
  560.       is is filled with NULL strings; these values are not considered
  561.       to be numeric.  You must assign values to the individual elements
  562.       before using them in expressions.  The second form can be used to
  563.       convert a simple variable into an array of one element; array
  564.       variables remain unchanged.  Arrays are singly dimensioned and are
  565.       limited to no more than 32767 elements.
  566.  
  567.  
  568.                                 BREAK
  569.       BREAK
  570.  
  571.       Break out of a while loop; execution continues with the next
  572.       command following the corresponding endwhile for the current
  573.       level of loop.  The BREAK command is used to prematurely exit a
  574.       loop.  BREAK is restricted to script files.
  575.  
  576.  
  577.                                 CAT
  578.       CAT
  579.       CAT [file....]
  580.  
  581.       Copies the specified files to stdout (the current window, unless
  582.       output has been redirected).  If you don't specify a file, stdin
  583.       is copied.  You can cat standard input along with other files by
  584.       specifying - (minus sign) alone as a file name.  You can also use
  585.       CAT to join binary files together by redirecting the output to a
  586.       file.
  587.  
  588.         % cat a                 types a to the current window
  589.         % cat - bar >foo        copies stdin + bar to foo
  590.         % cat a b c >prt:       copies a b and c to the printer
  591.  
  592.  
  593.                                 CD
  594.       CD
  595.       CD path
  596.  
  597.       Changes the current working directory.  You may use any of the
  598.       directory aliases here (see Directory Aliases in chap. 8).
  599.  
  600.       CD with no arguments changes the current directory to the
  601.       directory specified in the home variable, or if the home variable
  602.       is undefined, CD just displays the path of the current directory.
  603.  
  604.       If you enter a directory name by itself on a line, then bsh
  605.       implicitly changes the working directory to that dir.  This is
  606.       only done if the path search fails to find a command of the same
  607.       name and the dir name does not conflict with an internal command.
  608.  
  609.  
  610.                                 CLOSE
  611.       CLOSE fd...
  612.  
  613.       Close a file.  fd is the file descriptor returned by the open()
  614.       function.  The FILES command will list the file-names and
  615.       descriptor numbers of all open files.  You cannot use CLOSE to
  616.       close files opened by some other program.  Care should be used
  617.       with this command, as it is possible to close files which are
  618.       still in use such as script files and redirection files.
  619.  
  620.  
  621.                                 CONTINUE
  622.       CONTINUE
  623.  
  624.       Advance to the next iteration of a while loop; execution
  625.       continues with the while command at the top of the loop.
  626.       CONTINUE is restricted to script files.
  627.  
  628.  
  629.                                 CP
  630.       CP file... dev
  631.       CP [-AacdeNnu] file file
  632.       CP [-AacdeNnu] file... dir
  633.       CP [-AacdeNnru] dir... dir
  634.  
  635.         -A      Set archive bit on source files after successful copy.
  636.         -a      Set archive bit on destination files.
  637.         -c      Causes cp to copy the file-protection bits and comment
  638.                 from the original file to the destination file.
  639.                 Otherwise the protection mask is set to ----rwed.
  640.         -d      date - set file timestamp to current time and date.
  641.                 Default is to retain the original timestamp.
  642.         -e      Copy only files which already exist in destination
  643.                 directory.
  644.         -N      Copy only files which have been modified (archive bit
  645.                 is not set).
  646.         -n      Copy only files which do not exist in destination
  647.                 directory.
  648.         -r      Recursively copy all subdirectories.
  649.         -u      Update - copy file only if destination file is older
  650.                 or does not exist.
  651.  
  652.       Copies files and directories.  To recursively copy all
  653.       subdirectories of the directories specified on the command line,
  654.       the "-r" option must be used.  If "-r" is not specified, each
  655.       file in dir is copied, but none of the sub-directories in dir is
  656.       copied.  When copying recursively, directories will be created
  657.       automatically, if they do not already exist.
  658.  
  659.       Using the first form, it is possible to copy several files to a
  660.       DOS non-filing-system device (E.G. PRT:); in this case, there
  661.       are no applicable options.
  662.  
  663.       examples:
  664.  
  665.         % cp this that PRT:     # copy files to the printer
  666.         % cp -u ~ .             # copy files from the home directory to
  667.                                 # the current dir; only copy file if it
  668.                                 # is newer.
  669.         % cp *.c prt:           # copy all .c files in the current dir
  670.                                 # to the printer.
  671.  
  672.       CP has no quiet option but can be made to copy quietly by
  673.       redirecting stderr:
  674.  
  675.         % cp dir1 dir2 2>NIL:
  676.  
  677.  
  678.                                 ECHO
  679.       ECHO [-n] string...
  680.  
  681.       Write the strings to standard output (the current window unless
  682.       output has been redirected).  A newline character is appended to
  683.       the end of string unless '-n' is specified.
  684.  
  685.  
  686.                                 ELSE
  687.       ELSE
  688.  
  689.       ELSE clause of a block if; this toggles the value of the matching
  690.       IF condition.  Only one ELSE is allowed for each IF command.
  691.  
  692.  
  693.                                 ELSEIF
  694.       ELSEIF expression
  695.  
  696.       ELSEIF clause of a block if; if the matching IF condition was
  697.       true, it is now false; if it was false, it is now true if
  698.       expression evaluates to true (non-zero).  Any number of ELSEIFs
  699.       may be associated with one IF.
  700.  
  701.       example:
  702.  
  703.         if a < 10
  704.         ...
  705.         elseif a < 20
  706.         ...
  707.         else
  708.         ...
  709.         endif
  710.  
  711.  
  712.                                 ENDIF, FI
  713.       ENDIF
  714.       FI
  715.  
  716.       The end of the scope of a block IF statement.
  717.  
  718.  
  719.                                 ENDWHILE
  720.       ENDWHILE
  721.  
  722.       The of the scope of a while loop.
  723.  
  724.       See also WHILE
  725.  
  726.  
  727.                                 @, EVAL
  728.       @ expression
  729.       EVAL expression
  730.  
  731.       @ and EVAL both evaluate an expression (see expressions below)
  732.       After evaluating the expression, EVAL prints the value to the
  733.       standard output, whereas @ does not.  If the _debug variable is
  734.       set to 8, expression values are always printed to standard error
  735.       when evaluated.  If you enter an assignment expression on a line
  736.       by itself, bsh will execute an implied @ command using that
  737.       expression.  If you wish to redirect the output of EVAL, you
  738.       must place the redirection operator before the command name:
  739.  
  740.         % >foo eval 1+1
  741.  
  742.       it is not currently possible to pipe the output of eval to another
  743.       command.
  744.  
  745.       examples:
  746.  
  747.         % eval sqrt(4)
  748.         2.0000000
  749.         % @ j=5
  750.         % x=sin(.543)
  751.         % echo $x
  752.         0.51670675
  753.  
  754.       See also expressions in chapter 5.
  755.  
  756.  
  757.                                 EXPORT
  758.       EXPORT varname...
  759.  
  760.       Sets the export flag for varname; variables which have the
  761.       export flag set are exported to sub-shells of the current shell
  762.       (they inherit its value).  This includes all shells started by
  763.       bsh or newbsh commands from the current shell.  Script local
  764.       variables cannot be exported.
  765.  
  766.  
  767.                                 FILES
  768.       FILES
  769.  
  770.       Lists all files currently opened by bsh.  This includes files
  771.       opened by the open() function, files opened by redirection
  772.       ( >file ), and script files currently being executed.
  773.       Information includes the file name, the file descriptor number,
  774.       and whether the file was opened for read or write access.
  775.  
  776.  
  777.                                 FOREACH
  778.       FOREACH var ( list ) command...
  779.       FOREACH var ( list )
  780.          command
  781.          ...
  782.       END
  783.  
  784.       For each argument in list, the argument is assigned to the
  785.       variable var, and then each of the commands is executed in turn.
  786.       If more than one command is given with the first form, they must
  787.       be enclosed in quotes.  Foreach does not require a space between
  788.       the open parenthesis and the first argument; however if the first
  789.       argument contains a wildcard, then you must include the space for
  790.       wildcard expansion to work properly; the same is true between the
  791.       last argument and the closing parenthesis.  Only the first form
  792.       of FOREACH can be used in an alias definition.
  793.  
  794.         % foreach i (1 2 3) echo "$i is a digit"
  795.         1 is a digit
  796.         2 is a digit
  797.         3 is a digit
  798.  
  799.         % foreach i ( *.o )     # remove .o files
  800.         > j=basename(i)
  801.         > if -f $j.asm          # for which the source is in assembly
  802.         >     rm -q $i
  803.         > endif
  804.         > end
  805.  
  806.       FOREACH can be used to interpret arguments of a parameterized
  807.       alias:
  808.  
  809.         % alias xx "foreach i ( $! ) echo \$i"
  810.         % xx *                  echos the names of all files in the
  811.                                 current directory
  812.  
  813.       You may not use a GOTO or WHILE command inside a FOREACH; however
  814.       you can have calls to source scripts which do include GOTO and
  815.       WHILE commands.  Also it is not possible to nest FOREACH commands.
  816.  
  817.  
  818.                                 GOTO
  819.       GOTO label
  820.  
  821.       GOTO the named label.  Command execution continues with the
  822.       command immediately following the label.  GOTO is restricted
  823.       to script files.
  824.  
  825.  
  826.                                 HASH
  827.       HASH
  828.       HASH command
  829.       HASH command path
  830.  
  831.       Display the hash tree, display the hash-path for a command, add
  832.       a command and path to the hash tree.  Bsh searches the hash tree
  833.       when the hash-operator (#) is included in the path variable.
  834.       The use of this reduces the search time and disk accesses
  835.       required to locate an external (disk-based) command.  No action
  836.       by you is required to take advantage of this feature, as bsh
  837.       automatically adds names of commands to this tree when it finds
  838.       them while searching your path.  The HASH command allows you to
  839.       manipulate this tree.  The filename part of path need not match
  840.       command.
  841.  
  842.       Examples:
  843.  
  844.         % hash ls work:bin/ls   # add ls to the hash tree
  845.         % hash                  # display the hash tree
  846.         ls      work:bin/ls
  847.         vi      work:bin/z
  848.  
  849.       See also UNHASH, REHASH
  850.  
  851.  
  852.                                 HELP
  853.       HELP
  854.  
  855.       Displays all the bsh builtin commands and predefined functions.
  856.       The commands are displayed columnwise in alphabetical-order.
  857.  
  858.  
  859.                                 HIST
  860.       HIST [string]
  861.  
  862.       Displays the history list with event numbers (The number of
  863.       events remembered in the history list is determined by the
  864.       bsh _history variable).  If a string is specified, only those
  865.       entries starting with string are shown.
  866.  
  867.  
  868.                                 IF
  869.       IF expression
  870.       IF test expr
  871.  
  872.       Execute following commands (through ELSE/ELSEIF/ENDIF) if
  873.       expression evaluates to true (non-zero).  The IF command is not
  874.       restricted to source files, and may be used interactively.  You
  875.       can see whether the expression is true by using it with the
  876.       EVAL command.  The structure of an IF block is something like
  877.       this:
  878.  
  879.         if expression
  880.             commands
  881.             ...
  882.         elseif expression
  883.             commands
  884.             ...
  885.         elseif expression
  886.             commands
  887.             ...
  888.         else
  889.             commands
  890.             ...
  891.         endif
  892.  
  893.       The ELSEIF/ELSE clauses are of course optional.  If blocks may be
  894.       nested up to a maximum depth of 32.  The nesting depth is reset at
  895.       zero for each script file, so you could be nested at say level 23
  896.       in one script file called from another at a depth of 31.
  897.  
  898.       The second form of IF involving the test command is included
  899.       mainly for compatiblity with Bourne shell scripts.  See the
  900.       separate documentation for test for format of test expressions.
  901.       Bsh's own expression evaluation is much more powerful and easier
  902.       to use than that of the test command.
  903.  
  904.       examples:
  905.  
  906.         if a < 10               if variable a is less than 10
  907.             somecommand
  908.         endif
  909.         if -z fred              if file fred exists and is empty
  910.             mv fred ..
  911.         endif
  912.         if ?x                   if variable x has been defined
  913.             if a[5] != 0        if element 5 of a is non-zero
  914.                 x /= a[5]
  915.             else
  916.                 echo a[5] is zero
  917.             endif
  918.             eval x
  919.         endif
  920.  
  921.       See also expressions in chapter 5.
  922.  
  923.  
  924.                                 LABEL
  925.       LABEL name
  926.  
  927.       Define a label name; used as the object of a GOTO.  Labels can
  928.       only be used within a script file.  When LABEL is used, it
  929.       should be the first command on a line as GOTO can only branch
  930.       to line boundries.
  931.  
  932.  
  933.                                 LOCAL
  934.       LOCAL varname[=value]...
  935.       LOCAL arrayname[#elements]...
  936.  
  937.       LOCAL must be used from within a bsh script file; it creates a
  938.       variable local to that script.  If a global or environment
  939.       variable of the same name exists, it is masked (becomes
  940.       invisible) within the script.  In order for a variable to become
  941.       local to a script, it must be declared local (with the LOCAL
  942.       command) before any other reference to it.  When a script exits,
  943.       all variables local to that script are automatically destroyed.
  944.       You cannot initialize an array with the LOCAL command.
  945.  
  946.         % local i j=1 ar[20] k=2 l
  947.         % set ar {0,0,0,0,0}{0,0,0,0}   # initializes ar with zeros
  948.  
  949.  
  950.                                 MEM
  951.       MEM
  952.  
  953.       Display memory availability for CHIP and FAST memory.  The
  954.       advantage of using MEM over Avail is that MEM is an internal
  955.       command and thus does not disturb the memory availability in
  956.       order to print it.
  957.  
  958.  
  959.                                 MKDIR
  960.       MKDIR name name name...
  961.  
  962.       Create directories.  If name already exists, MKDIR returns
  963.       exit-status 5 (WARN) if name was a directory, or exit-status
  964.       10 (ERROR) if name was a plain file.
  965.  
  966.  
  967.                                 MV
  968.       MV from to
  969.       MV from... todir
  970.  
  971.       Rename a file or move one or more files or directories to a
  972.       different directory.  If todir is "/" or "..", the files are
  973.       moved to the parent directory; if todir is ".", the files are
  974.       moved into the current directory.  Currently MV cannot move
  975.       files across devices (MV df0:a df1:).  MV will complain if you
  976.       try to move a directory inside itself or inside one of its
  977.       subdirectories.  MV returns an exit-status of 10 (ERROR) if the
  978.       destination file already exists or todir does not exist or your
  979.       try to mv a dir inside itself.
  980.  
  981.  
  982.                                 ONERR, ONINTR
  983.       ONERR command...
  984.       ONINTR command...
  985.  
  986.       ONINTR specifies the command(s) to be executed when an interrupt
  987.       (^C,^D) is encountered when executing a script.  If ONINTR has
  988.       been specified, the interrupt signals are reset before executing
  989.       the command(s).  ONERR specifies the commands to be executed when
  990.       an error occurs while executing a script.  See also the onerr,
  991.       and onintr variables.  You can also set a global ONERR, which
  992.       specifies commands to be executed if an error occurs while
  993.       executing commands entered interactively, from the command line.
  994.       If multiple commands are given, they must be enclosed in quotes.
  995.  
  996.  
  997.                                 PICK
  998.       PICK [item...]
  999.  
  1000.       PICK prompts you for every item specified on the command line, and
  1001.       for each item you respond positively, writes its name to standard
  1002.       out.  If no items are specified, PICK reads its standard input for
  1003.       items, one item per line.  For each item in the list, PICK prompts
  1004.       with:
  1005.  
  1006.         item [ynaveq] ?
  1007.  
  1008.       available responses are:
  1009.         y       yes, choose this item
  1010.         n       no, do not choose this item
  1011.         a       select this item, and all remaining items in the list
  1012.         v       view this item; uses program specified in the environment
  1013.                 variable PAGER to view the item.  If the variable PAGER
  1014.                 does not exist, the program More is used.  This only makes
  1015.                 sense if item is a file.
  1016.         e       edit this item; uses program specified in the environment
  1017.                 variable EDITOR to edit the item.  If the variable EDITOR
  1018.                 does not exist, the program Ed is used.  This only makes
  1019.                 sense if item is a file.
  1020.         q       quit
  1021.         !cmd    run cmd.  A '%' character in the command is replaced by
  1022.                 the current item.
  1023.  
  1024.       PICK is best used to restrict command line arguments generated by
  1025.       wildcard search or by some other program:
  1026.  
  1027.         % cp `pick *.c` df1:foo         select which *.c files to copy
  1028.         % mv `find . -print | pick` a   select which files to move from
  1029.                                         list generated by 'find' to dir a.
  1030.         % pick * | zoo aI foo.zoo       select which files to archive
  1031.  
  1032.  
  1033.                                 PRINTENV
  1034.       PRINTENV
  1035.  
  1036.       Displays the values of the environment variables.  PRINTENV only
  1037.       displays those files in the ENV: directory (not in subdirectories).
  1038.  
  1039.  
  1040.                                 PWD
  1041.       PWD
  1042.       PWD file...
  1043.  
  1044.       Print the current directory name if no files given.  If files are
  1045.       specified, the absolute DOS path to each is printed.
  1046.  
  1047.  
  1048.                                 QUIT
  1049.       QUIT [value]
  1050.  
  1051.       Quit bsh.  If you specify a value, bsh exits with the optional
  1052.       exit-code.  (see RETURN below)
  1053.  
  1054.  
  1055.                                 READ
  1056.       READ varname...
  1057.  
  1058.       Read variable(s) from stdin.  One line is read and split according
  1059.       to IFS (see special variables).  Data are matched with the
  1060.       specified variable names.  Any excess data is discarded; if there
  1061.       is less data than variables, the remaining variables are set to
  1062.       the null string ("").  You cannot read an entire array just by
  1063.       specifying the array name; you must list the individual elements
  1064.       to be read.
  1065.  
  1066.         % read a b c[2] c[3]
  1067.  
  1068.  
  1069.                                 REHASH
  1070.       REHASH
  1071.  
  1072.       Delete the entire hash tree.  See the discussion under HASH above.
  1073.  
  1074.  
  1075.                                 REPEAT
  1076.       REPEAT count command
  1077.  
  1078.       Repeatedly execute a command.  The count can be an expression but
  1079.       if it contains any of '|; ><' you will have to enclose it in
  1080.       quotes.  Command may be several commands separated by semi-colons.
  1081.       If it is, the entire list of commands should be enclosed in quotes.
  1082.       You may not use a GOTO, WHILE or FOREACH command inside a REPEAT.
  1083.  
  1084.  
  1085.                                 EXIT, RETURN
  1086.       EXIT [expression]
  1087.       RETURN [expression]
  1088.  
  1089.       Return from a script file.  If given, the expression value becomes
  1090.       the return value for the SOURCE command.  In a function script,
  1091.       this value is RETURN'ed as the function value.  In a startup
  1092.       script, EXIT functions as a QUIT command, that is bsh is prevented
  1093.       from going into interactive mode; once bsh has gone into interactive
  1094.       mode, EXIT functions only as a return.  This allows you to set up
  1095.       scripts which will run normally if entered from the command line,
  1096.       but quit after running the script when entered:
  1097.  
  1098.         % bsh <scriptfilename>
  1099.  
  1100.  
  1101.                                 REWIND
  1102.       REWIND fd...
  1103.  
  1104.       Rewind a file; the file is positioned at its beginning.  Fd is a
  1105.       file descriptor returned by the open() function.
  1106.  
  1107.  
  1108.                                 RM
  1109.       RM [-iqr] file...
  1110.  
  1111.       Delete the specified files or empty directories.  Use the "-r"
  1112.       option to remove non-empty directories by recursively removing
  1113.       all sub directories and files they contain.  The -i option will
  1114.       cause bsh to prompt for each file with:
  1115.  
  1116.         filename [ynaveq] ?
  1117.  
  1118.       before it is deleted; see the PICK command for responses.  RM
  1119.       returns errorcode 5 (WARN) if the file did not exist or 10
  1120.       (ERROR) if RM could not delete the file because it was busy.
  1121.       The -q option causes RM to do its work quietly, otherwise each
  1122.       file is listed as it is deleted.
  1123.  
  1124.  
  1125.                                 SET
  1126.       SET
  1127.       SET name
  1128.       SET name string...
  1129.  
  1130.       The first form displays all bsh variables and their values.  The
  1131.       second form displays the value for a single variable.  The last
  1132.       form sets a variable to a string or array of strings.  To include
  1133.       a space in the value for a variable, you must quote the value.
  1134.  
  1135.       See also UNSET
  1136.       see the section on special variables below
  1137.  
  1138.  
  1139.                                 SETENV
  1140.       SETENV name string
  1141.  
  1142.       Set an environment variable.  The environment variables are really
  1143.       files in the ENV: directory.  This probably should be assigned to
  1144.       some directory on your ram: disk by your startup-sequence.
  1145.       Environment variables are referenced in the same way as other bsh
  1146.       variables with the exception that environment variable names are
  1147.       not case sensitive.  If an environment variable and a bsh variable
  1148.       have the same name, the bsh variable overrides.  Also environment
  1149.       variables cannot be arrays at this time.
  1150.  
  1151.         % setenv NAME Fred
  1152.         % echo $name
  1153.         Fred
  1154.  
  1155.  
  1156.                                 SLEEP
  1157.       SLEEP [time]
  1158.  
  1159.       Sleep for <time> seconds.  If <time> is not specified, bsh takes
  1160.       a one second nap.  Time may be specified with or without a
  1161.       fractional part (n.nn).  The resolution of <time> is .02 seconds.
  1162.  
  1163.  
  1164.                                 SOURCE
  1165.       SOURCE script-file [arguments]
  1166.  
  1167.       Execute a script file.  Normally, you just type file [arguments];
  1168.       the main advantage to specifying SOURCE explicitly is that it
  1169.       does not require that the script and execute permission bits be
  1170.       set for the file.  Note that when you specify SOURCE explicitly,
  1171.       the path is not searched for file; you must specify the path for
  1172.       the file unless it is in the current directory.  Arguments are
  1173.       passed via the argv[] variable.  The name of the source script
  1174.       is in argv[0], the ith argument to the script is in argv[i].
  1175.       See also argv under special variables in chap. 4.  Some commands
  1176.       such as GOTO and WHILE can only be used in script files.
  1177.  
  1178.       Scripts are useful to replace a frequently used or long sequence
  1179.       of commands with a single, easy to remember command.  They are
  1180.       also useful in dealing with some program's clumsy user interface.
  1181.       Also, scripts can often be used in place of a C program, and are
  1182.       much easier to write and debug.  For more info on script
  1183.       programming, see chapter 7.
  1184.  
  1185.  
  1186.                                 THEN
  1187.       THEN
  1188.  
  1189.       THEN does absolutely nothing whatsoever.  It is included only for
  1190.       compatibility with Bourne-shell scripts.
  1191.  
  1192.  
  1193.                                 UNALIAS
  1194.       UNALIAS name...
  1195.  
  1196.       Removes bsh aliases from the alias tree.
  1197.  
  1198.       See also ALIAS
  1199.  
  1200.  
  1201.                                 UNHASH
  1202.       UNHASH command
  1203.  
  1204.       Removes a command name from the hash tree.
  1205.  
  1206.       See also HASH, REHASH
  1207.  
  1208.  
  1209.                                 UNSET
  1210.       UNSET name....
  1211.  
  1212.       Removes bsh variables from the variable tree and frees all space
  1213.       used by each for strings, arrays.
  1214.  
  1215.       See also SET
  1216.  
  1217.  
  1218.                                 UNSETENV
  1219.       UNSETENV name....
  1220.  
  1221.       Removes the named environment variables.  This deletes the
  1222.       ENV:name file.
  1223.  
  1224.       See also SETENV
  1225.  
  1226.  
  1227.                                 VER
  1228.       VER
  1229.  
  1230.       Displays the version number of bsh, along with its date.
  1231.  
  1232.  
  1233.                                 WHILE
  1234.       WHILE expression
  1235.  
  1236.       Repeat statements while expression is true (non-zero).  WHILE can
  1237.       only be used in script files.  While loops may be nested up to a
  1238.       maximum depth of 10.
  1239.  
  1240.       example:
  1241.  
  1242.         while a < 10
  1243.             a++
  1244.             ...
  1245.         endwhile
  1246.  
  1247.       See also expressions in chapter 5.
  1248.       See also ENDWHILE
  1249.  
  1250.  
  1251.                                 WINDOW
  1252.       WINDOW [parent | child]
  1253.       WINDOW [back | front | activate | zip]
  1254.       WINDOW x y width height
  1255.       WINDOW
  1256.  
  1257.       Manipulate the bsh window.  Using this command, you can move
  1258.       the bsh window in back of all other windows, in front of all
  1259.       other windows, activate the window, change its dimensions,
  1260.       toggle between two sizes (zip, requires DOS 2.0), or activate
  1261.       the child or parent of the shell's window.  Be careful - you
  1262.       can set the window width and height to zero if it has no size
  1263.       gadget; the window will then be very hard to find.  Also, any
  1264.       changes to the window size made while the window is not the
  1265.       active window are apparently missed by the console (I think
  1266.       this is fixed in DOS2.0)  With no arguments, WINDOW prints the
  1267.       current window coordinates and bounds; you can use this to save
  1268.       the current window bounds and restore them later:
  1269.  
  1270.                 % set wndw `window`     # save current window bounds
  1271.                 % window 0 0 640 400    # change window size...
  1272.                         ...
  1273.                 % window $wndw          # restore window to previous
  1274.                                         # bounds
  1275.  
  1276.       The zip function requires AmigaDOS2.04 to operate.
  1277.       Keyword arguments may be abbreviated to a single letter.
  1278.  
  1279.  
  1280.  
  1281.  
  1282.     3-2                     OTHER COMMANDS
  1283.  
  1284.  
  1285.                                 BSH
  1286.       BSH [-a] [startup-script]...
  1287.       BSH -c command;command...
  1288.  
  1289.       Startup a bsh shell in the current CLI window.  The -a switch
  1290.       is useful when you want to suppress bsh's command-line editing
  1291.       features.  It is possible to use the command-line editing features
  1292.       in an AUX: CLI.  The second form can be used to gain bsh services
  1293.       in running a command (i.e. wildcards, pipe, etc.).  At startup,
  1294.       bsh first reads and executes the file .bshrc in the current
  1295.       directory if it exists, or s:.bshrc.  Next if the -c switch was
  1296.       selected, command is executed and bsh then quits, else any startup
  1297.       scripts specified on the command line are executed.  Then bsh
  1298.       executes the file .login in the current directory if it exists,
  1299.       or s:.login and then enters interactive mode.  If a QUIT or EXIT
  1300.       command was encountered during execution of a startup script, bsh
  1301.       will quit without entering interactive mode.
  1302.  
  1303.  
  1304.                                 NEWBSH
  1305.       NEWBSH [window-spec] [-a] [[FROM] startup-script...]
  1306.       NEWBSH [window-spec] -c command...
  1307.  
  1308.       Startup a new bsh shell in a different window.  The FROM keyword
  1309.       is only required if the first argument would be a startup script,
  1310.       to distinguish it from a window specification.  NEWBSH can be
  1311.       started from WorkBench by double-clicking on the NEWBSH tool
  1312.       icon, or by double clicking on a script icon.  Some sample icons
  1313.       are provided.  You can also extended select several script icons,
  1314.       and NEWBSH will execute each of them in turn.  If any of the
  1315.       scripts contain a QUIT or EXIT command, NEWBSH will quit after
  1316.       executing all of the scripts; otherwise NEWBSH will enter
  1317.       interactive mode, accepting command input.
  1318.    4-0                         VARIABLES
  1319.  
  1320.  
  1321.     Bsh like other shells uses only string variables.  However, some
  1322.     commands that work with expressions, can perform arithmetic on
  1323.     these variables as numbers.  These special commands are @, EVAL,
  1324.     IF, ELSEIF, RETURN, and WHILE.  In this context, a numeric variable
  1325.     is really a string variable that contains only digits with a leading
  1326.     sign or hexadecimal radix (0x), a decimal point and an exponent.
  1327.     Internally, variables are stored in a binary tree for fast access.
  1328.  
  1329.     A variable name consists of any number of characters chosen from
  1330.     letters, digits and the underscore.
  1331.  
  1332.     Variables may be set (assigned a value) by the SET command, or by
  1333.     use of an assignment operator in an expression.
  1334.  
  1335.  
  1336.     4-1                   VARIABLE SUBSTITUTION
  1337.  
  1338.     When a variable has been assigned a value, bsh replaces occurences
  1339.     of that variable on command lines with the assigned value.  Bsh
  1340.     recognizes a word as a variable if it begins with a dollar sign.
  1341.     You can protect a word from variable substitution by preceding the
  1342.     dollar sign with a backslash (\$).  Variable substitution occurs
  1343.     even if the variable name occurs within a string enclosed in double
  1344.     quotes, but not in a string enclosed in single quotes.  Environment
  1345.     variables are referenced in the same manner as regular bsh
  1346.     variables on the command line; however they cannot be assigned a
  1347.     value in an expression.  Within an expression, variables are
  1348.     referenced without the leading dollar sign.
  1349.  
  1350.  
  1351.     4-2                     ARRAY VARIABLES
  1352.  
  1353.     Before you can manipulate the elements of an array, the entire array
  1354.     must be declared.  Arrays can only be declared using the SET, or
  1355.     ARRAY commands:
  1356.  
  1357.         % set days Sunday Monday Tuesday Wednesday Thursday Friday Saturday
  1358.  
  1359.         % echo $days
  1360.         Sunday Monday Tuesday Wednesday Thursday Friday Saturday
  1361.  
  1362.     Individual array elements may be referenced by postfixing the array
  1363.     name with an element number enclosed in square brackets; the
  1364.     element number can also be a numeric variable.  A range of elements
  1365.     can be referenced by the first element number followed by a dash
  1366.     followed by the last element number.  An asterisk can be used to
  1367.     indicate all elements of the array, an asterisk can be used after
  1368.     the dash to indicate the last element of the array.
  1369.  
  1370.         % echo $days[3]
  1371.         Wednesday
  1372.  
  1373.         % echo $days[1-5]
  1374.         Monday Tuesday Wednesday Thursday Friday
  1375.  
  1376.         % set i 2
  1377.         % echo $days[$i]
  1378.         Tuesday
  1379.  
  1380.         % echo $days[$i-*]
  1381.         Tuesday Wednesday Thursday Friday Saturday
  1382.  
  1383.     All elements must be assigned a value when the array is declared
  1384.     (a NULL or 0 may be used if the desired value will not be known
  1385.     until later).  The SET command counts the number of items on the
  1386.     command line and allocates enough memory for that many elements.
  1387.     The ARRAY command allocates enough storage for the specified
  1388.     number of elements, and fills them all with NULLs.
  1389.  
  1390.  
  1391.     4-3                  SPECIAL VARIABLE FORMS
  1392.  
  1393.     The number of elements of an array can be referenced by using the
  1394.     form:
  1395.  
  1396.     $#array_name
  1397.  
  1398.     The existence of a variable can be queried by the form:
  1399.  
  1400.     $?var_name
  1401.  
  1402.     This form returns 1 if var_name has been defined, and 0 if it has
  1403.     not been defined.  You can also use this to determine whether an
  1404.     array has a specified number of elements:
  1405.  
  1406.     $?array[5]
  1407.  
  1408.     returns a 1 if array has at least 6 elements.
  1409.  
  1410.     You can catenate a plain string to the end of a variable on the
  1411.     command line if you enclose the variable name in braces:
  1412.  
  1413.     % set dow Sun
  1414.     % echo ${dow}day
  1415.     Sunday
  1416.  
  1417.  
  1418.     4-4                   SPECIAL VARIABLES
  1419.  
  1420.     Variable names starting with an underscore ('_') have a one to one
  1421.     connection with flags/counters deep in the heart of bsh.  For this
  1422.     reason, their intended effect cannot be accomplished using environ-
  1423.     ment, or local environment variables.
  1424.  
  1425.  
  1426.     argv
  1427.     *
  1428.         This array variable contains the arguments passed to a script
  1429.         program.  Each argument is an element of the array.  For
  1430.         example:
  1431.  
  1432.                     script-file printargs
  1433.             local i
  1434.             echo $argv
  1435.             echo $*
  1436.             set i 0
  1437.             while i < #argv
  1438.                 echo argv[$i] = $argv[$i]
  1439.                 i++
  1440.             endwhile
  1441.  
  1442.         % printargs 1 2 4
  1443.         printargs 1 2 4
  1444.         1 2 4
  1445.         argv[0] = printargs
  1446.         argv[1] = 1
  1447.         argv[2] = 2
  1448.         argv[3] = 4
  1449.  
  1450.         Individual arguments may be addressed as $argv[4], $argv[$i]...
  1451.         argv[0] contains the script file name; the remaining arguments
  1452.         may be referenced as a group by $*.  $* is equivalent to
  1453.         $argv[1-*].  Any of the first 10 elements may be referenced by
  1454.         short form; $1 is equivalent to $argv[1]...
  1455.  
  1456.  
  1457.     commands
  1458.         Contains the count of commands executed since bsh was started.
  1459.         This is maintained by bsh, however, it is not always updated
  1460.         after every command; if you exececute a script file, it will
  1461.         not be updated until the script completes.  This variable is
  1462.         read-only.
  1463.  
  1464.  
  1465.     cwd
  1466.         Contains the absolute path of the current working directory.
  1467.         This variable is maintained by bsh each time you change the
  1468.         working directory with a CD command or an external (disk-based)
  1469.         command changes the current directory.  This variable is read-only.
  1470.  
  1471.  
  1472.     _debug
  1473.         Debug modes.  The following debug modes are supported:
  1474.                  0      no debugging
  1475.                  1      print command arguments prior to executing
  1476.                         each command
  1477.                  2      print redirection file names (console is
  1478.                         indicated by an asterisk).
  1479.                  4      print depth of variable names in variable
  1480.                         tree (applies to set, hash, local and alias
  1481.                         commands only).
  1482.                  8      print expression values when they are evaluated
  1483.                         (by @, EVAL, IF, ELSEIF, RETURN, WHILE)
  1484.                 16      print exit status, and DOS error number after
  1485.                         each command executed.
  1486.                 32      print actual command line (after all variable
  1487.                         substitutions, and wild-card expansion).  As an
  1488.                         alternative to _verbose, this prints only those
  1489.                         commands that are actually executed.  If used
  1490.                         with mode 2, both outputs are combined on 1 line.
  1491.  
  1492.         Set _debug to the sum of the desired debugging modes.  Debugging
  1493.         output is written to the stderr file.  _debug must be a bsh
  1494.         variable (not an environment variable for this to have any effect).
  1495.  
  1496.  
  1497.     errno
  1498.         This variable contains the DOS error number from the last command.
  1499.         To obtain an English translation, feed it to Fault:
  1500.  
  1501.                 % Fault $errno
  1502.  
  1503.         Remember that this variable is reset after each command, so you
  1504.         will have to assign it to some other variable first if you plan
  1505.         to manipulate it.  For the custom bsh error numbers, you can use
  1506.         the error script provided:
  1507.  
  1508.                 % error 909
  1509.                 error 909: reference to undefined variable
  1510.  
  1511.  
  1512.     height
  1513.         Maintained by bsh, this is the height of the console window in
  1514.         lines.  If you resize the window, bsh will update this variable
  1515.         to reflect the change.
  1516.  
  1517.  
  1518.     histnum
  1519.         This variable contains the event number of the next command to be
  1520.         executed.  This value is substituted for '!' in the prompt or
  1521.         title.  This variable is read-only.
  1522.  
  1523.  
  1524.     _history
  1525.         This variable specifies the number of history events bsh should
  1526.         retain.  Consecutive identical history items are entered in the
  1527.         history list only once.  _history must be a bsh variable (not an
  1528.         environment variable for this to have any effect).
  1529.  
  1530.  
  1531.     home
  1532.         This is the home directory variable; it contains the full path
  1533.         specification for the home directory.  It is substituted for a
  1534.         leading ~ in file name/path specifications.  This variable is
  1535.         automatically set by bsh at startup, but you can alter it at any
  1536.         time.
  1537.  
  1538.         examples:
  1539.  
  1540.         % cp ~/foo .    copies the file foo from the home directory
  1541.                         to the current directory.
  1542.         % ls ~          lists the files in the home directory.
  1543.  
  1544.  
  1545.     IFS
  1546.         Contains the characters that serve as argument separators when
  1547.         command output is being substituted on the command line or when
  1548.         variables are being read (READ command).  If IFS is not set,
  1549.         the value " \n\t" (space, new-line, tab) is used.
  1550.  
  1551.  
  1552.     _ignoreeof
  1553.         If defined, EOF is ignored on consoles.  Use this to prevent
  1554.         accidentally exiting bsh.  You can still exit bsh by entering
  1555.         the QUIT command.  _ignoreeof must be a bsh variable (not an
  1556.         environment variable for this to have any effect).
  1557.  
  1558.  
  1559.     insert
  1560.         This variable controls the default screen insert/overlay mode.
  1561.         If insert is set to 0 (zero), the default mode is overlay, else
  1562.         mode defaults to insert.  If insert is not set, insert is the
  1563.         default mode.  Of course you can always toggle between modes
  1564.         by typing a ^A during command entry.
  1565.  
  1566.  
  1567.     _noclobber
  1568.         If set to some value, output redirection will fail if the file
  1569.         already exists; append redirection will fail unless the file
  1570.         already exists.  Use of this variable can sometimes keep you
  1571.         from accidently clobbering an important file.  _noclobber must
  1572.         be a bsh variable (not an environment variable for this to have
  1573.         any effect).
  1574.  
  1575.  
  1576.     _noglob
  1577.         If set to some value, inhibits wildcard expansion.  Use this if
  1578.         you want an external program to do it's own wildcard expansion,
  1579.         or when symbols normally used as wildcards have a different
  1580.         meaning.  _noglob must be a bsh variable (not an environment
  1581.         variable for this to have any effect).
  1582.  
  1583.  
  1584.     _nonomatch
  1585.         If set to some value, will not complain when a wildcard string
  1586.         fails to find a match; instead, if the match fails, the string
  1587.         will be passed on to the command to be executed.  _nonomatch
  1588.         must be a bsh variable (not an environment variable for this to
  1589.         have any effect).
  1590.  
  1591.  
  1592.     _noreq
  1593.         If set to some value, will disable requesters ("Please insert
  1594.         volume fred in any drive") during the path search for external
  1595.         commands.  _noreq must be a bsh variable (not an environment
  1596.         variable for this to have any effect).
  1597.  
  1598.  
  1599.     path
  1600.         This contains the search paths used to find external commands.
  1601.         path is an array variable containing a list of directory-names
  1602.         to be searched, and optionally some special elements:
  1603.             '!'     Search the CLI path.  This does not include the
  1604.                     current directory, or C:.  See the example set path
  1605.                     below for how to include them.
  1606.             '#'     Look for the command in the hash list.
  1607.             '0'     Turn off requesters for following directories.  If
  1608.                     path contains, say, fred:c, and volume fred: is not
  1609.                     mounted, you can avoid a requester saying "Please
  1610.                     insert volume fred in any drive".
  1611.             '1'     Turn requesters back on.
  1612.         The path variable is not used if the command is in the system
  1613.         RESIDENT list, or the command name contains pathing information
  1614.         (contains a ':' or '/').  The suggested set value for path is
  1615.  
  1616.             % set path '.' '#' '!' sys:scripts c:
  1617.  
  1618.         This assumes that your bsh scripts are in the sys:scripts directory.
  1619.         There is no default value for path.
  1620.  
  1621.  
  1622.     pipe
  1623.         This variable contains the name of the pipe device which will be
  1624.         used when piping output from one command to input of another.  If
  1625.         pipe is undefined, temporary ram: files are used instead.  If set
  1626.         to "PIP:", it is assumed to be a conman PIP: pipe device; case is
  1627.         significant.
  1628.  
  1629.  
  1630.     prompt
  1631.         This string is displayed when bsh is expecting interactive input
  1632.         from the user.  Special characters recognized are:
  1633.                 !       the value of the variable histnum (event number)
  1634.                 `       the current time (HH:MM)
  1635.                 ``      the current time (HH:MM:SS)
  1636.                 \       used to protect the following character from
  1637.                         interpretation; to get a \, use \\.
  1638.                 $name   the value of the variable name (any bsh variable)
  1639.                         If this should be evaluated each time the prompt
  1640.                         is printed, the name should be escaped as in
  1641.                         \$name; this will prevent the command parser from
  1642.                         evaluating the variable immediately.
  1643.  
  1644.         If commands are being skipped because you executed an IF command,
  1645.         bsh changes the prompt to "? ".  You must then enter an endif
  1646.         command before command execution resumes.
  1647.  
  1648.  
  1649.     PS2
  1650.         This is the secondary prompt used when bsh is expecting interactive
  1651.         input from the foreach command:
  1652.  
  1653.         % set PS2 "huh? "
  1654.         % foreach i ( a b )
  1655.         huh? echo $i
  1656.         huh? end
  1657.         a
  1658.         b
  1659.  
  1660.         If PS2 is not defined, the value "> " is used.
  1661.  
  1662.  
  1663.     status
  1664.         Exit-status of the last command.  This is set after each command
  1665.         executed, so it is necessary to query this immediately or its
  1666.         value will have changed.
  1667.  
  1668.  
  1669.     _title
  1670.         This string is printed in the window title line.  Special
  1671.         character processing is the same as for the prompt string.  _title
  1672.         must be a bsh variable (not an environment variable for this to
  1673.         have any effect).
  1674.  
  1675.  
  1676.     _umask
  1677.         This variable controls the permission bits set for files opened
  1678.         by bsh for output redirection.  The variable must be set to the
  1679.         sum of the desired permission bit values (use 15 for rwed, 13
  1680.         for rw-d, etc).  The permissions for the file are set after the
  1681.         file is closed.  _umask must be a bsh variable (not an environment
  1682.         variable for this to have any effect).
  1683.  
  1684.  
  1685.     _verbose
  1686.         Enter verbose mode (for scripts).  This mode displays commands as
  1687.         they are read from the script file.  Debugging output is written
  1688.         to the stderr file.  _verbose must be a bsh variable (not an
  1689.         environment variable for this to have any effect).
  1690.  
  1691.  
  1692.     width
  1693.         Maintained by bsh, this is the console width in chars.  If you
  1694.         resize the window, bsh will update this variable to reflect the
  1695.         change.
  1696.    5-0                         EXPRESSIONS
  1697.  
  1698.     The commands - @, ELSEIF, EVAL, IF, RETURN, and WHILE evaluate and
  1699.     utilize C-like expressions in the perfomance of their functions.
  1700.     Expressions consist of strings, numeric constants, bsh variables,
  1701.     function references and operators.  You can freely insert spaces
  1702.     anywhere in an expression except in compound operators variable
  1703.     names or numeric strings.  Within expressions variable names may
  1704.     be used without the leading dollar sign ($).  If you use a leading
  1705.     dollar sign, the variable is replaced by the command parser and
  1706.     looks like a constant to the expression evaluator.  Numerical
  1707.     operations are performed on 32-bit signed ints or 32-bit FFP
  1708.     floating point operands.  Variables have no intrinsic type, but
  1709.     assume the type of the data they contain.  The arithmetic and
  1710.     relational operators will all allow mixed mode operands.  That is
  1711.     an int can be added to a floating point operand or compared to
  1712.     a floating point operand; in this case, the int is first converted
  1713.     to floating point and then the operation is performed.  Environment
  1714.     variables may also be used within expressions, but may not be
  1715.     altered by an assignment operator within an expression; use the
  1716.     setenv command to alter environment variables.
  1717.  
  1718.  
  1719.     5-1                         OPERATORS
  1720.  
  1721.     The following is a list of bsh operators in order of precedence
  1722.     from highest to lowest.
  1723.  
  1724.         ()      override precedence of operators
  1725.         ?var    test the existence of a variable (this is similar to the
  1726.                 $?var special form [see chap. 4-3]).
  1727.         #array  number of elements in an array (this is similar to the
  1728.                 $#array special form [see chap. 4-3]).
  1729.         ~       unary one's complement
  1730.         !       logical not
  1731.         -       unary minus
  1732.         ++      increment a bsh variable (var++, ++var)
  1733.         --      decrement a bsh variable (var--, --var)
  1734.         %       modulus
  1735.         /       division
  1736.         *       multiplication
  1737.         -       subtraction
  1738.         +       addition
  1739.         <<      left shift
  1740.         >>      right shift
  1741.         >       greater
  1742.         <       less
  1743.         >=      greater or equal
  1744.         <=      less or equal
  1745.         !=      not equal
  1746.         ==      equal
  1747.         &       logical product
  1748.         |       logical sum
  1749.         ^       exclusive or
  1750.         &&      logical and
  1751.         ||      logical or
  1752.         =       assign a value to a bsh variable
  1753.         +=      increment the value of a bsh variable
  1754.         -=      decrement the value of a bsh variable
  1755.         *=      multiply the value of a bsh variable
  1756.         /=      divide the value of a bsh variable
  1757.         %=      assign the modulus value of a bsh variable
  1758.         ,       comma operator (comma is a binary operator which
  1759.                 returns the value of the subexpression to the right
  1760.                 of the comma).  That is, a = (b,c) assigns the value
  1761.                 of c to a.  The comma is also used to separate
  1762.                 function parameters, and to separate multiple
  1763.                 assignments in an expression:
  1764.  
  1765.                     % a=1,b=2,c=3
  1766.  
  1767.     IMPORTANT: The decrement and increment operators are pre-increment
  1768.     (++var) and post-increment (var++).  In either case, the variable
  1769.     is incremented, but the value used in the expression is that of
  1770.     the variable before incrementing (post-increment) or after
  1771.     incrementing (pre-increment).  That is, if i has the value of 1,
  1772.     then j = i++ assigns the value of 1 to j while incrementing i to 2.
  1773.     These operators can only be used with integers.
  1774.  
  1775.     In addition, file operators operate on following filename.
  1776.     Boolean operators:
  1777.  
  1778.         -A      file has been archived
  1779.         -D      file has delete access
  1780.         -d      file is a directory file
  1781.         -e      file exists
  1782.         -f      file is a plain file
  1783.         -o      file exists
  1784.         -P      file is pure
  1785.         -r      file has read access
  1786.         -S      file is a script file
  1787.         -w      file is writeable
  1788.         -x      file is executable
  1789.         -z      file is empty
  1790.  
  1791.     Operators which return a value:
  1792.  
  1793.         -m      time of last modification (seconds since 1/1/1978)
  1794.         -p      file protection string (hsparwed)
  1795.         -s      size of file in bytes
  1796.         -T      date file was last modified
  1797.         -t      time file was last modified
  1798.  
  1799.     Examples:
  1800.         % eval str=-T fred
  1801.         26-Nov-89
  1802.  
  1803.         % eval str=-p fred
  1804.         ----rwed
  1805.  
  1806.         % if -f fred
  1807.         % echo fred is a plain file
  1808.         % endif
  1809.  
  1810.     A variable containing a file name must be prefixed by a dollar sign ($)
  1811.     when it is the object of a file operator.
  1812.  
  1813.         % if -s $file > 1000
  1814.         % echo $file is larger than 1000 bytes
  1815.         % endif
  1816.  
  1817.  
  1818.     5-2                 FUNCTIONS
  1819.  
  1820.     The following functions are predefined by bsh:
  1821.  
  1822.           abs(num)
  1823.         returns the absolute value of num.
  1824.  
  1825.           acos(num)
  1826.         returns the angle whose cosine is num.
  1827.  
  1828.           asin(num)
  1829.         returns the angle whose sine is num.
  1830.  
  1831.           atan(num)
  1832.         returns the angle whose tangent is num.
  1833.  
  1834.           basename(str)
  1835.         returns the base filename of str.  If str is "foo.c",
  1836.         basename(str) returns "foo".
  1837.  
  1838.           cat(str1,str2,...)
  1839.         concatenates strings.
  1840.  
  1841.           char(num)
  1842.         returns the character whose ascii value is num.  This provides a
  1843.         means to convert small integers to characters.
  1844.  
  1845.           cos(num)
  1846.         returns the cosine of num.
  1847.  
  1848.           cosh(num)
  1849.         returns the hyperbolic cosine of num.
  1850.  
  1851.           date()
  1852.         returns the current date in MM/DD/YY format.
  1853.  
  1854.           devname(str)
  1855.         returns the device name portion of string.  If str is
  1856.         "df1:foo", devname(str) returns "df1".
  1857.  
  1858.           eof(fd)
  1859.         returns true if EOF was read on file fd (fd is a file
  1860.         descriptor number as returned by open()).  Calling the eof()
  1861.         function has the side-effect of clearing the EOF condition for
  1862.         the file.
  1863.  
  1864.           exp(num)
  1865.         returns the exponential of num (e**num).
  1866.  
  1867.           filename(str)
  1868.         returns the file-name stripped of path.
  1869.  
  1870.           float(num)
  1871.         converts an integer to floating point.
  1872.  
  1873.           getchar()
  1874.         reads a character from stdin and returns it.
  1875.  
  1876.           hex(num)
  1877.         converts num to a hexadecimal string.
  1878.  
  1879.           index(str,"c")
  1880.         returns the position of first occurence of "c" in str.  Returns
  1881.         -1 if "c" not found in str.
  1882.                 % eval index("abc","c")
  1883.                 2
  1884.                 % eval index("abc",99)      99 is the ascii value of 'c'
  1885.                 2
  1886.  
  1887.           int(num)
  1888.         converts num to integer.
  1889.  
  1890.           left(str,num)
  1891.         returns the leftmost num characters in str.
  1892.  
  1893.           log(num)
  1894.         returns the natural logarithm of num.
  1895.  
  1896.           log10(num)
  1897.         returns the base 10 logarithm of num.
  1898.  
  1899.           lower(str)
  1900.         returns str transformed to lower case.
  1901.  
  1902.           max(num1,num2)
  1903.         returns the maximum of two numbers.
  1904.  
  1905.           min(num1,num2)
  1906.         returns the minimum of two numbers.
  1907.  
  1908.           mounted(device)
  1909.         returns true if device has been mounted and bsh is able to
  1910.         obtain a lock on it; this only works for filing-system devices.
  1911.  
  1912.           numeric(str)
  1913.         returns true if str is a numeric string.
  1914.  
  1915.           open(filename,mode)
  1916.         opens a file, and returns the file descriptor number.  Available
  1917.         modes are:
  1918.             "a" - append
  1919.             "r" - read
  1920.             "w" - write
  1921.  
  1922.           pathname(str)
  1923.         returns the path name portion of string.
  1924.  
  1925.           pow(base,exp)
  1926.         returns base raised to the exp power.  This is a floating point
  1927.         function, but will return an integer if both arguments are
  1928.         integer.
  1929.  
  1930.           ran(max)
  1931.         generates a random integer in the range (0 <= num < max).  Max
  1932.         must be < 4194304 (2**22).
  1933.  
  1934.           right(str,num)
  1935.         returns the rightmost num characters in str.
  1936.  
  1937.           rindex(str,"c")
  1938.         returns the position of last occurence of "c" in str.  Returns
  1939.         -1 if "c" not found in str.  See also index.
  1940.  
  1941.           rtime()
  1942.         returns the number of ticks since midnight.  There are 50 ticks
  1943.         per second.
  1944.  
  1945.           sin(num)
  1946.         returns the sine of num.
  1947.  
  1948.           sinh(num)
  1949.         returns the hyperbolic sine of num.
  1950.  
  1951.           size(var)
  1952.         returns the size of array (1 indicates scalar, 0 undefined)
  1953.  
  1954.           sqrt(num)
  1955.         returns the square root of num.
  1956.  
  1957.           strlen(str)
  1958.         returns the length of str.
  1959.  
  1960.           substr(str,first,len)
  1961.         extracts a substring from a string starting with character
  1962.         numbered first, of length len.
  1963.                 % eval substr("abcdefg",3,3)
  1964.                 cde
  1965.  
  1966.           tan(num)
  1967.         returns the tangent of num.
  1968.  
  1969.           tanh(num)
  1970.         returns the hyperbolic tangent of num.
  1971.  
  1972.           time()
  1973.         returns the current time in HH:MM:SS format.
  1974.  
  1975.           upper(str)
  1976.         returns str transformed to upper case.
  1977.  
  1978.  
  1979.     Additionally, any bsh script file may be used as a function; it
  1980.     returns a value via the RETURN command.  As with any other bsh script,
  1981.     arguments are passed to the function in the argv variable:
  1982.  
  1983.     funcname([arg]...)      user defined function
  1984.  
  1985.     File funcname must be somewhere in your path.
  1986.    6-0                 REDIRECTION AND PIPES
  1987.  
  1988.  
  1989.     You can now specify the type of PIPE you wish to use in the bsh
  1990.     variable pipe.  If this variable is undefined, PIPES are
  1991.     implimented as temporary ram: files.  These files are
  1992.     automatically deleted upon completion of the pipe segment.  To use
  1993.     the new 1.3 Pipe.device, you need only set the pipe variable:
  1994.  
  1995.         % set pipe PIPE:
  1996.  
  1997.     To use the Conman pip: device as a pipe:
  1998.  
  1999.         % set pipe PIP:
  2000.  
  2001.     Case is significant.  You should probably place one of the above
  2002.     commands in your s:.bshrc file.  Of course, whichever pipe you use,
  2003.     you will have to Mount it before using it; this should probably be
  2004.     done in your startup-sequence.
  2005.  
  2006.     If the pipe variable is set, bsh will run pipe segments in the
  2007.     background as separate processes, if they are external commands.
  2008.     This allows the pipe reader to start execution as soon as the pipe
  2009.     feeder produces some output instead of waiting for it to complete.
  2010.     As of version 1.0, a script which is executed as a pipe feeder,
  2011.     will be run in a sub-shell in the background; this is also true
  2012.     for a script run by the background operator '&'.
  2013.  
  2014.         % script1 | wc      Script1 runs in a subshell in the
  2015.                             background, while wc counts its
  2016.                             output.
  2017.         % script1 &         Script1 just runs in the background.
  2018.  
  2019.  
  2020.     It is now possible to redirect standard input and standard output
  2021.     to any file opened with the open() function.  For example:
  2022.  
  2023.         % j=open("foo","w")
  2024.         % cmd >&$j
  2025.         % close $j
  2026.  
  2027.     The output from cmd has been placed in file foo just as if you had
  2028.     typed:
  2029.  
  2030.         % cmd >foo
  2031.  
  2032.     Output can be appended to the end of a file by using the append
  2033.     redirection operator:
  2034.  
  2035.         % cmd >>foo
  2036.  
  2037.  
  2038.     The standard error file can can be redirected for internal bsh
  2039.     commands only (bsh will redirect standard error for external
  2040.     commands when running under AmigaDOS2.0 or higher.  Even then,
  2041.     this will only work for those commands which check for DOS2.0 and
  2042.     the pr_CES field in the process structure.)
  2043.  
  2044.         % cmd 2>foo         Redirect error messages from cmd to
  2045.                             file foo.
  2046.  
  2047.         % cmd1 2>>foo       Appends error messages to the end of
  2048.                             file foo.
  2049.  
  2050.         % cmd1 2>&1 | cmd2  Sends error messages down the pipe
  2051.                             along with regular output.
  2052.  
  2053.  
  2054.     A special form of input-file redirection is the here document;
  2055.     this allows you to include data for a program in a script
  2056.     immediately following the command invocation:
  2057.  
  2058.         % prog <<some-string-of-your-choice
  2059.         this is data line 1
  2060.         this is data line 2
  2061.         ...
  2062.         some-string-of-your-choice
  2063.  
  2064.     The lines of data are copied to a ram: temporary file, and input
  2065.     is redirected from that file.
  2066.    7-0                     SCRIPT PROGRAMMING
  2067.  
  2068.     Scripts are run as any other command, that is, if you type "foo",
  2069.     and the script file foo exists in your current directory or your
  2070.     search path, it is run automatically as though you had typed
  2071.     "source foo".  For this "automatic sourcing" to occur, the script
  2072.     file must have the SCRIPT and EXECUTE permission bits set:
  2073.  
  2074.         % protect foo +se
  2075.  
  2076.     You can also input or output redirect scripts the same as any
  2077.     other program.  Script output may also be piped to a different
  2078.     program, however currently, the script does not run in parallel
  2079.     and the pipe is a temporary ram: file.  In version 1.0 of bsh,
  2080.     these scripts will run in parallel in a separate shell.
  2081.     Parameters may be passed to scripts and are available to the
  2082.     script program in the local array argv.  Argv[0] contains the
  2083.     script name, and the remaining elements contain the actual
  2084.     parameters.
  2085.  
  2086.  
  2087.     7-1                         LOOPING
  2088.  
  2089.     Looping in scripts is accomplished using the WHILE or GOTO
  2090.     commands.
  2091.     Example:
  2092.         i = 1
  2093.         while i < 99
  2094.             cmd1
  2095.             if whatever
  2096.                 break
  2097.             endif
  2098.             i++
  2099.         endwhile
  2100.  
  2101.     Bsh branches within scripts by Seeking to the new location.
  2102.     Because bsh cannot currently seek to the middle of a line, the
  2103.     WHILE and LABEL commands must be the first command on a line.
  2104.     Small loops (less than 1024 bytes) can be fit in a buffer and thus
  2105.     eliminate disk thrashing.
  2106.  
  2107.  
  2108.     7-2                     ARGUMENT PASSING
  2109.  
  2110.     Arguments are passed to scripts in the argv array variable.  This
  2111.     variable is local to the called script and is always an array,
  2112.     even if no arguments were specified.  Argv[0] contains the script
  2113.     name, as specified on the command line.  The remaining arguments
  2114.     are in argv[1] thru argv[n], where n is the number of arguments.
  2115.     The first ten arguments can be referenced in a short-hand way; $0
  2116.     refers to $argv[0], $9 refers to $argv[9].  The notation $* refers
  2117.     to all arguments after the script name, that is: $argv[1] ...
  2118.     $argv[n].  $argv[*] refers to all arguments including the script
  2119.     name, that is: $argv[0] ... $argv[n].
  2120.  
  2121.     The argv array is only a copy of the strings passed to the script,
  2122.     so you can safely alter elements of the array or even UNSET the
  2123.     array.
  2124.  
  2125.     The following program fragment shows how a script might examine its
  2126.     arguments looking for keywords.
  2127.  
  2128.         i = 1, list = 0, delete = 0, move = 0
  2129.         while i < #argv
  2130.             if lower(argv[i]) == 'list'
  2131.                 list = 1
  2132.             elseif lower(argv[i]) == 'delete'
  2133.                 delete = 1
  2134.             elseif lower(argv[i]) == 'move'
  2135.                 move = 1
  2136.             endif
  2137.             i++
  2138.         endwhile
  2139.  
  2140.  
  2141.     7-3           EXCEPTION PROCESSING and INTERRUPTS
  2142.  
  2143.     If no onerr variable exists, any command which fails causes the
  2144.     script to abort as though a RETURN command had been executed.  A
  2145.     command fails if its exit status is >= the FailLevel set by the
  2146.     FailAt command.  The script will then return that value as its own
  2147.     exit status.  The onerr variable is set by the ONERR command:
  2148.  
  2149.         % onerr "stt=status,err=errno; cmd1; cmd2..."
  2150.  
  2151.     While bsh is executing a script, if a command fails with
  2152.     exit-status >= FailLevel, bsh then checks for the onerr variable.
  2153.     If the onerr variable exists, then the error status is cleared and
  2154.     the commands specified in the onerr variable are executed;
  2155.     execution then resumes with the next command unless the onerr
  2156.     contained a GOTO, RETURN or ABORT command.  The ABORT command can
  2157.     restore the exit-status:
  2158.  
  2159.         % onerr "stt=status,err=errno; cmd1; cmd2...; abort $stt $err"
  2160.  
  2161.     While bsh is executing a script, if a ^C (control-C) or ^D
  2162.     (control-D) signal is received, bsh then checks for the onintr
  2163.     variable (the onintr variable is set by the ONINTR command).  If
  2164.     the onintr variable exists, then the signals are cleared, and the
  2165.     commands specified in the onintr variable are executed; execution
  2166.     then resumes with the next command unless the onintr contained a
  2167.     GOTO, RETURN or ABORT command.
  2168.  
  2169.     Each script has its own onerr, and onintr variables; thus they can
  2170.     safely reference labels in the script file.
  2171.  
  2172.     The onerr/onintr commands should probably include one of RETURN or
  2173.     GOTO or ABORT.  This will ensure that an error in a pipe-line
  2174.     causes the pipe-line to be aborted.
  2175.    8-0                     DIRECTORY ALIASES
  2176.  
  2177.  
  2178.     Any argument of a command can make use of the directory alias
  2179.     feature.  To use this, the argument must start with one of the
  2180.     directory aliases:
  2181.  
  2182.         .       the current directory.
  2183.         ..      the parent directory of the current dir.
  2184.         ./foo   the file 'foo' in the current directory.
  2185.         ../foo  the file 'foo' in the parent of the current dir.
  2186.         ~       the home dir (specified by the home variable).
  2187.         ~/foo   the file 'foo' in the home dir.
  2188.  
  2189.     The ../ operator may be applied repetitively to higher and higher
  2190.     levels until you reach the root of a device:
  2191.  
  2192.         ../../f the file 'f' in the parent of the parent of the
  2193.                 current dir.
  2194.         ~/../f  the file 'f' in the parent of the home dir.
  2195.  
  2196.     All of the directory alias substitutions are replaced with
  2197.     absolute path names; if you are currently in fred:a/b/c:
  2198.  
  2199.         % echo ../../foo
  2200.         fred:a/foo
  2201.         % echo //foo
  2202.         //foo
  2203.    9-0                     PROBLEMS
  2204.  
  2205.  
  2206.  
  2207.     Do not redirect the RUN command. to redirect the command the RUN
  2208.     command is running, include a standard CLI redirection in the
  2209.     command string:
  2210.  
  2211.         % RUN "command >file"
  2212.  
  2213.                             --------
  2214.  
  2215.     You need to give bsh sufficient stack space, especially if you
  2216.     will be running recursive shell scripts.  8192 is sufficient
  2217.     for the maximum recursion depth (16).  Stack should be run BEFORE
  2218.     invoking bsh.  Running it from within bsh does not affect bsh's
  2219.     stack size.  You don't need to worry about stack for newbsh, if
  2220.     called from a CLI; in this case newbsh allocates a stack of 8192
  2221.     bytes for itself.  Stacksize set in newbsh tool icons or script
  2222.     project icons should be set to at least 8192.
  2223.  
  2224.                             --------
  2225.  
  2226.     Programs which use Manx or Lattice stdio can sometimes cause the
  2227.     conman PIP: pipe-handler to crash.  This is NOT a bug in bsh.
  2228.     You can ignore the requester and the next time you use a pipe,
  2229.     the PIP: pipe-handler will be reloaded.
  2230.  
  2231.                             --------
  2232.  
  2233.     There is a bug in the new, DOS 2.04, Queue-Handler (V37 PIPE)
  2234.     which causes the pipe writer program to hang if the the pipe
  2235.     reader completes first.  To see this try:
  2236.  
  2237.         % mount PIPE:
  2238.         % set pipe PIPE:
  2239.         % type <some-file-bigger-than-12k> | More
  2240.  
  2241.     when More starts up, type q (for quit).  You will now have a
  2242.     hung process "type" which bsh is waiting to complete.  If you
  2243.     type a ^E (control-E), you should see a line that looks like:
  2244.  
  2245.         wait proc: type, procno 1, level 1
  2246.  
  2247.     If you type a ^F (control-F), bsh will move that process (and all
  2248.     others that it is waiting on) to the background, and once again
  2249.     accept command input.  If you execute the FILES command you should
  2250.     see a line that looks like:
  2251.  
  2252.         FILE: 3, 7EXXXXX/1FXXXXX, name = PIPE:A123456789, Write
  2253.  
  2254.     Now type:
  2255.  
  2256.         % cat PIPE:A123456789 >NIL:
  2257.  
  2258.     The background "type" process should complete and go away.  As an
  2259.     alternative to this process, you could continue to use the V36
  2260.     PIPE (Pipe-Handler); in your mountlist change L:Queue-Handler to
  2261.     L:Pipe-Handler, and change Stacksize = 3000 to Stacksize = 6000.
  2262.     If you updated from V36 to V37 using the 2.04 install disk, you
  2263.     should find Pipe-Handler in the System2.0:old directory.
  2264.  
  2265.                             --------
  2266.  
  2267.     Conman CNC: and CND: handlers apparently discard type-ahead when
  2268.     bsh toggles in and out of raw mode.  If type-ahead is important
  2269.     to you, use regular CON: or NEWCON: console windows.  Alternately,
  2270.     if you want to use Conman features, use the -a option when starting
  2271.     bsh or newbsh; this will disable the switch to raw mode.
  2272.  
  2273.                             --------
  2274.  
  2275.     "Say" does something funky to the console after which, it is
  2276.     impossible to place it in raw mode.  This has the effect of making
  2277.     bsh appear to hang.  You can escape by typing a ^\ (control-\) to
  2278.     get out of bsh.  If you started by bsh (not newbsh), you should
  2279.     EndCLI this CLI, as other programs which need to place the console
  2280.     in raw mode will hang.
  2281.  
  2282.                             --------
  2283.  
  2284.     It is not possible, currently, to redirect a parameterized alias
  2285.     which contains pipe segments.  That is
  2286.  
  2287.         % alias lx "ls $! | grep -v \.info"
  2288.         % lx >foo
  2289.  
  2290.     will now get error 904: redirection error.
  2291.  
  2292.                             --------
  2293.  
  2294.     Bsh does not run under AmigaDOS1.1 or older systems; bsh uses
  2295.     several Exec, DOS, and Intuition library calls new to the 1.2 OS
  2296.     release.  If there is a great deal of interest in this, I may
  2297.     provide a DOS1.1 compatible version.  But this would be very
  2298.     difficult as the Manx SDB debugger also does not run under
  2299.     DOS1.1.  Why are you running DOS1.1 anyway?  This version is
  2300.     obsolete.
  2301.