home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / sysutl / sh1_111.arc / SH1.DOC < prev    next >
Text File  |  1987-10-26  |  43KB  |  1,063 lines

  1. Sh1   Documentation     Version 1.11    Date 10-23-87
  2.  
  3. Table of contents
  4. ------------------
  5.  Disclaimer, Trademarks, my name and address etc. . . . . Section  0
  6.  Description. . . . . . . . . . . . . . . . . . . . . . . Section  1
  7.  History of changes and bug fixes . . . . . . . . . . . . Section  2
  8.  The commands that are built into sh1 . . . . . . . . . . Section  3
  9.  Algebraic and Logical Expression Format (in BNF) . . . . Section  4
  10.  Variables and their uses . . . . . . . . . . . . . . . . Section  5
  11.  Using output of programs in command strings. . . . . . . Section  6
  12.  History of Commands buffer . . . . . . . . . . . . . . . Section  7
  13.  shx shell extention program. . . . . . . . . . . . . . . Section  8
  14.  Shell files. . . . . . . . . . . . . . . . . . . . . . . Section  9
  15.  Compiling shell files. . . . . . . . . . . . . . . . . . Section 10
  16.  Defining the prompt and sh1 temporary file directory . . Section 11
  17.  Bugs and other funny phenomena . . . . . . . . . . . . . Section 12
  18.  History of changes up to V1.08A inclusive. . . . . . . . Appendix A
  19.  Shx usage examples . . . . . . . . . . . . . . . . . . . Appendix B
  20.  
  21.  
  22. Section 0. Disclaimer, Trademarks, my name and address etc.
  23.  
  24.   I make no representation or warranties with respect to the
  25.   contents hereof and specifically disclaim any implied warranties
  26.   to the suitability of this program for any particular purpose.
  27.   You must determine that yourself.  In addition, you should
  28.   understand that using a program of this type on an IBM PC or
  29.   compatible has inherent risks and that you may inadvertently
  30.   damage or destroy valuable programs or data.  I expressly
  31.   decline to assume liability for any use of this program by you,
  32.   and your use of this program constitutes your agreement to hold
  33.   me blameless.
  34.  
  35.   BUT if someone finds a bug and goes to the trouble of telling me,
  36.   I would be more than happy to fix it and upload an update.
  37.   I also welcome any other comments and suggestions.
  38.  
  39.   MS-DOS is a registered trademark of Microsoft Corporation.
  40.   PC-DOS is a registered trademark of IBM Corporation.
  41.   IBM PC is a registered trademark of IBM Corporation.
  42.  
  43.   If you find this program to be of benefit to you, please send any
  44.   contribution ($10 suggested) to me so I can spend more time on
  45.   improving this program and writing other such programs.
  46.  
  47.   Thanks...
  48.  
  49.   Noam Naaman
  50.   406 Prospect Ave #4K
  51.   Hackensack, NJ 07601
  52.   (201) 343-7242
  53.  
  54.  
  55.   You may leave me a message on one of these fine bulletin board
  56.   systems (all operating at 2400 Baud, 8 bits, no parity):
  57.  
  58.     The Right Choice    (201) 974-8317
  59.     CloneWorld          (201) 290-1183
  60.     BOSS                (201) 568-7293
  61.  
  62. Section 1. Description
  63.  
  64.    Sh1 is a shell program written out of frustration of having
  65.    to deal with MS(PC)-DOS command.com's idiotic interface.
  66.  
  67.   I tried to implement as many features of Unix as time permitted.
  68.   Some of the enhancements of this shell over command.com are:
  69.  
  70.     1.1. Environment variables can actually be of use.
  71.  
  72.     1.2. Batch files can be nested to a depth of 8 ( Hurray!!!)
  73.  
  74.     1.3. History of commands:
  75.       1.3.1 Re-execute a command
  76.       1.3.2 Edit a command
  77.       1.3.3 Delete a command
  78.       1.3.4 Clear all commands
  79.  
  80.     1.4. Batch files (shell files a la Unix) can pipe output of one program
  81.        into a command line (e.g. SAVEPATH=`cd` will assign the current dir
  82.        to an environment variable by the name of SAVEPATH )
  83.  
  84.     1.5. "while", "case" and "if else endif" constructs are implemented and
  85.        may be nested.
  86.  
  87.     1.6. Procedures may be defined and called.
  88.  
  89.     1.7. An accompanying utility "shx.exe" extends the proramability of sh1
  90.        even further. Functions of shx.exe are:
  91.       1.7.1 String handling: substring extraction, position, delete, insert
  92.       1.7.2 Return size of file
  93.       1.7.3 Create file containing an expanded list of wildcard parameters
  94.  
  95.   Sh1 searches for an executable file in the following order:
  96.    - .COM and .EXE files.
  97.    - .SHC compiled shells (See section 10).
  98.    - .SH regular shells (See section 9).
  99.  
  100. Section 2. History of changes and bug fixes.
  101.  
  102.   In order to make this section more "enjoyable", info on versions up to
  103.   1.08A inclusive, has been moved to Appendix A.
  104.  
  105.   2.17 V1.09
  106.  
  107.        Version 1.08A had a bug creap in which would crash the system on default 
  108.        disk change. FIXED.
  109.        Added two new options to shx:
  110.         shx -ms allows setting the modification date of a file.
  111.         shx -so allows overlaying one string over another.
  112.  
  113.   2.17 V1.10
  114.  
  115.        Sh1 recognizes a new type shell files with a suffix of .SHC which stands
  116.        for compiled shell. Once you have a working shell, you may use the new
  117.        SHC.EXE to tokenize the shell and and save it under the same name but 
  118.        with the new suffix .SHC. Most of the keywords are translated to a one 
  119.        byte code and all leading spaces are deleted. See section 10 for more
  120.        details.
  121.  
  122.        The gotoxy command has been enhanced to accept two full algebraic
  123.        expressions separated by a space.
  124.  
  125.        A new unary NOT operator has been added to algebraic expressions. The
  126.        NOT operator is the ! character.
  127.  
  128.        Procedures may now get up to 9 parameters. See CALL description and
  129.        section 5.
  130.  
  131.   2.18 V1.11
  132.  
  133.        One-dimensional arrays may be created and referenced (See section 5).
  134.  
  135.        New debugging commands: break on procedure name and break on return,
  136.        view whole application output screen (p, r and v respectively).
  137.  
  138.        Shx has a new option -scrt for painting the screen from a regular
  139.        text file  instead of a file created with the -scrs option.
  140.  
  141.        The ACCEPT command returns a code in the %? variable that indicates
  142.        which key was pressed to exit the line editing.
  143.        The return codes are:
  144.         13 for [Return]
  145.         27 for [Esc]
  146.         72 for Up arrow
  147.         73 for PgUp
  148.         80 for Down arrow
  149.         81 for PgDn
  150.  
  151.        A new appendix B has been added, showing some ways of using Shx.
  152.  
  153. Section 3. The commands that are built into sh1
  154.  
  155.  (note: commands preceded by * may be executed only in a shell file )
  156.  
  157.  3.1 ACCEPT         Accept a string from keyboard and store in an environment
  158.                     variable. If a -e is inserted between the ACCEPT and the
  159.                     variable name, the contents of the variable will be 
  160.                     displayed and edited.
  161.  
  162.        accept GETSTRING
  163.  
  164.        accept -e REEDIT
  165.  
  166.        
  167.                     ACCEPT returns a code which may be accessed with the %?
  168.                     special variable. This code will tell which key caused
  169.                     the ACCEPT to exit editing. The return codes are:
  170.                      13 for [Return]
  171.                      27 for [Esc]
  172.                      72 for Up arrow
  173.                      73 for PgUp
  174.                      80 for Down arrow
  175.                      81 for PgDn
  176.  
  177.  3.2 *BREAK         Break out of case block or loop. The BREAK will cause
  178.                     the shell to continue execution at the first statement
  179.                     following a CASE, REPEAT-UNTIL, WHILE or FOR block it
  180.                     is currently in. A break statement will exit only
  181.                     one block level.
  182.  
  183.  3.3 *CALL          Call procedure with optional parameters. Up to 9 Parameters 
  184.                     may follow the procedure name on the calling line.
  185.                     Procedure name is case sensitive.
  186.      *RETURN        Return from procedure.
  187.      *PROCEDURE     Procedure declaration.
  188.  
  189.        call ABC substring
  190.        echo %RETSTRING
  191.        exit
  192.  
  193.        procedure ABC
  194.        RETSTRING=return this string with addition of %.1
  195.        return
  196.  
  197.       On return, RETSTRING=return this string with addition of substring
  198.  
  199.  3.4 *CASE          The parameter following the CASE stmt is compared to
  200.      *ENDCASE       case specifiers enclosed by endcase command.
  201.                     Each specifier is a string terminated with *) .
  202.                     default*) if given will be chosen if none of the preceding
  203.                     specifiers were chosen. You may specify multiple cases per
  204.                     line but you may not group the default*) with any other
  205.                     case.
  206.  
  207.        case %STR
  208.          1*)
  209.            echo STR = 1
  210.            break
  211.          2*)
  212.            echo STR = 2
  213.            break
  214.          3*) 4*) 5*)
  215.            echo STR = 3 thru 5
  216.            break
  217.          default*)
  218.            echo STR is either > 5 or < 1
  219.            break
  220.        endcase
  221.  
  222.  3.5 CHDIR         Same as command.com
  223.      CD
  224.  
  225.  3.6 CLEOL         Clear to end of line.
  226.  
  227.  3.7 CLOSE         Close any file opened by OPEN command.
  228.  
  229.        close 1      closes file #1
  230.        close *      closes all open files
  231.  
  232.  3.8 CLS           Same as command.com
  233.  
  234.  3.9 COMPUTE       Do arithmetic operations on environment variables containing
  235.                    numeric strings.
  236.  
  237.        compute ACC=%ACC + `shx -fz filename`
  238.        compute ACC=%ACC - %SECONDVAR
  239.        compute ACC=%ACC * 10 + 5
  240.        compute ACC=(%ACC / (%B + 2)) | 128
  241.  
  242.  3.10 COPY         Same as command.com
  243.  
  244.  3.11 DATE         Same as command.com
  245.  
  246.  3.12 DEBUG        Debug command execution in shell files. Debug may be followed
  247.                    with a '+' to turn debug on, '-' to turn debug off or nothing
  248.                    to cause debug flag to toggle. Please see section 9 for more
  249.                    details on debugging.
  250.        debug +
  251.        debug -
  252.        debug
  253.  
  254.  3.13 DEL          Same as command.com
  255.  
  256.  3.14 DIR          Same as command.com
  257.  
  258.  3.15 ECHO         Echo may work as in command.com or as a block echo
  259.                    using ! as delimiter. The echo may be redirected to a file
  260.                    by adding > or >> and a file name after closing exclamation
  261.                    point. Each echo is limited to 2000 characters.
  262.                    The keywords IF, WHILE and REPEAT should not be put as the 
  263.                    first words in any of the multiline echo lines to avoid
  264.                    confusing sh1.
  265.                    If you wish to cause the cursor to stay to the right of
  266.                    the string, put an underline as last character on echo line.
  267.  
  268.        echo this string will be printed on screen followed by a newline.
  269.        echo this string will be printed on screen without newline_
  270.  
  271.        echo !
  272.        This is a multi-line echo string.
  273.        In case the closing ! is followed by > filename then this text will
  274.        be written to filename.
  275.        In case the closing ! is followed by >> filename then this text will
  276.        be appended to filename.
  277.        !
  278.  
  279.  3.16 ERASE       Same as command.com
  280.  
  281.  3.17 *EXIT       Exit from shell execution. Optional numeric value may
  282.                   follow. The calling shell can access this return value with
  283.                   the %? special variable.
  284.  
  285.        exit %R      Exit current shell and return the value currently in 
  286.                     the R variable.
  287.  
  288.  3.18 EXITSH1       Exit back to good ol' command.com.
  289.                     Sh1 will return ERRORLEVEL 0 as default but if exitsh1 is
  290.                     followed by number, sh1 will return that number.
  291.  
  292.        exitsh1
  293.  
  294.  3.19 *FOR          A For loop will expand a list of filenames and assign each
  295.       *ENDFOR       element of the list to the specified variable. As long as
  296.                     the list is not exhausted, the commands between the FOR
  297.                     and ENDFOR will be executed. A second variation on the FOR 
  298.                     command is the INFILE which takes its arguments from a
  299.                     pre-existing text file. 
  300.                     In this version, FOR commands CANNOT BE NESTED.
  301.                     Sh1 MUST have access to SHX.EXE for this command to work.
  302.                     The syntax is: 
  303.                             FOR <var> IN <list>
  304.                             FOR <var> INFILE <textfile>
  305.  
  306.       for XX in *.C *.bak           Will expand the wildcard specifications.
  307.         echo %XX
  308.       endfor
  309.  
  310.       for XX infile FLNAMES.TXT     Will read words from FLNAMES.TXT files.
  311.         echo %XX
  312.       endfor
  313.  
  314.  3.20 GOTOXY       Positions cursor on screen.
  315.                    Followed by two algebraic expressions. The first expression
  316.                    gives the value of X while the second gives the value of Y.
  317.  
  318.        gotoxy 1 1
  319.        gotoxy %VARX+2  2*%VARY-5
  320.  
  321.  3.21 HIST         Access history of commands. Can also be invoked by
  322.                    pressing the Up arrow.
  323.  
  324.  3.22 *IF          If statements may compare two strings, two numbers,
  325.       *ELSE        test if a file exists or check for pending keyboard input.
  326.       *ENDIF       See expression format below.
  327.       *ELSE IF     The else-if construct can be repeated as often as desired.
  328.  
  329.       if %COUNT < 10 + %UPPERLIMIT
  330.         compute COUNT=%COUNT + 1
  331.       else if %COUNT > 20 &  %COUNT < 40
  332.         compute COUNT=%COUNT - 2
  333.       else
  334.         echo COUNT is equal to or greater than 10 and less than 21
  335.       endif
  336.  
  337.  3.23 LOCAL        Defines environment variables as local to the current shell
  338.                    and shell which are called by the current shell. On exiting
  339.                    the current shell, all variables appearing on this line,
  340.                    will be removed from environment. This line should be the
  341.                    first executable line of the shell. Only one LOCAL line per 
  342.                    shell is allowed.
  343.                    Please note that there can be only one variable of the same 
  344.                    name in the environment. If one shell calls another and the 
  345.                    called shell removes a variable used by the calling shell, 
  346.                    that variable will be lost to the calling shell.
  347.  
  348.       local ThisVar ThatVar TheOtherVar
  349.  
  350.  3.24 MKDIR        Same as command.com
  351.       MD
  352.  
  353.  3.25 OPEN         Open up to eight files for I/O mode as in the C language.
  354.  
  355.        open 1 filename r       Open file for reading
  356.        open 2 filename w       Open file for writing
  357.        open 3 filename a       Open file for writing, append text at eof
  358.        open 1 filename r+      Open file for read/write, file must exist
  359.        open 4 filename w+      Open file for read/write, create if DNE
  360.        open 4 filename a+      Open file for read/append, create if DNE
  361.  
  362.  3.26 READ         Read from an opened file a line of text and store in an
  363.                    environment variable.
  364.  
  365.        read 1 INLINE        Will read from file #1
  366.        read f WORD          Will read the next word from the FOR list if
  367.                             a FOR loop is currently active.
  368.  
  369.  3.27 REN          Same as command.com
  370.  
  371.  3.28 RMDIR        Same as command.com
  372.       RD
  373.  
  374.  3.29 SET          Set shows the currently defined environment variables.
  375.                    It is an internal command of sh1. If you pipe its
  376.                    output to a file, you will in actuality be executing
  377.                    the COMMAND.COM set command which, in addition
  378.                    to the variables, will show some hidden environment
  379.                    strings such as ;C_FILE_INFO and a few "not used".
  380.  
  381.  3.30 *SHIFT       Same as command.com
  382.  
  383.  3.31 SHOWSTAT     Show status of system. May be embedded in shell files for
  384.                    debugging purposes.
  385.  
  386.  3.32 TIME         Same as command.com
  387.  
  388.  3.33 TRACE        Trace command execution in shell files. Trace may be followed
  389.                    with a '+' to turn trace on, '-' to turn trace off or nothing
  390.                    to cause trace flag to toggle.
  391.        trace +
  392.        trace -
  393.        trace
  394.  
  395.  
  396.  3.34 TYPE         Same as command.com
  397.  
  398.  3.35 *WHILE       While loops will execute enclosed commands as long as
  399.       *ENDWHILE    expression returns TRUE. See expression format below.
  400.  
  401.       COUNT=1
  402.       while %COUNT < 10
  403.         compute COUNT=%COUNT+1
  404.         gotoxy 30 10
  405.         echo %COUNT
  406.       endwhile
  407.  
  408.  3.36 *REPEAT      The Repeat loop is the opposite of the While loop in that
  409.       *UNTIL       it checks for loop repeat at the end of the loop.
  410.  
  411.       N=1
  412.       repeat
  413.         echo %N
  414.         compute N=%N+1
  415.       until %N > 20
  416.  
  417.  
  418.  3.37 WRITE        Write a string into an open file.
  419.  
  420.        write 2 %OUTLINE
  421.        write 2 put this string into file 2
  422.  
  423.  
  424. Section 4. Algebraic and Logical Expression Format (in BNF)
  425.  
  426.   <expr>  ::= <expr0>
  427.               <expr0> | <expr0>          ( Or  )
  428.               <expr0> & <expr0>          ( And )
  429.  
  430.   <expr0> ::= <expr1>
  431.               <expr1> <relational operator> <expr1>
  432.  
  433.   <expr1> ::= <expr2>
  434.               <expr2> + <expr2>
  435.               <expr2> - <expr2>
  436.  
  437.   <expr2> ::= <expr3>
  438.               <expr3> * <expr3>
  439.               <expr3> / <expr3>
  440.  
  441.   <expr3> ::= <number>
  442.               'string' <relational operator> 'string'
  443.               ( <expr> )
  444.               ! <expr>                          Unary NOT operator
  445.               -f <filename>                     test for existance of file
  446.               -k                                test for keyboard input
  447.  
  448.   <number> ::= <digits>
  449.                -<digits>
  450.  
  451.   <digits> ::= <digit>
  452.                <digits><digit>
  453.  
  454.   <relational operator> may be ==  !=  >=  <=  >  <
  455.  
  456.   Examples:
  457.  
  458.     %VAR == 10
  459.     %VAR1 < %VAR2
  460.     %VAR2 + 5 * %VAR1
  461.  
  462.     '%PATH' != '`cd`'
  463.  
  464.     -f sh1.exe                                  test for presence of file
  465.     ! -f sh1.exe                                test for absence of file
  466.  
  467.     -k                                          test for keyboard input
  468.  
  469.  
  470.  
  471.   Comparisons may be combined to form a more complicated test.
  472.   The two operators & (and) and | (or) separate between comparisons:
  473.     %1 < %R  &  %2 > %S
  474.     '%1' == '%STR'  |  %2 < %NUM
  475.  
  476.   Compute commands assign a value to a variable by evaluating an
  477.   algebraic expression which may also include comparisons. Any
  478.   comparison yields either a "-1" if true or "0" if false:
  479.  
  480.     compute N = (1 > 2) * 20            will assign the value 0 to N.
  481.     compute N = (1 < 2) * 20            will assign the value 20 to N.
  482.  
  483. Section 5. Variables and their uses.
  484.  
  485.   Any environment variable may be assigned a string by simply typing
  486.   the variable's name followed by = followed by any string:
  487.  
  488.     DUMMYVAR=dummy string
  489.  
  490.   The contents of a variable may be accessed by preceding the variable name
  491.   with %.
  492.  
  493.     echo %PATH
  494.     PATH=%PATH;c:\anotherdir
  495.  
  496.   Creating and accesssing one-dimentional arrays of variables is accomplished
  497.   by using an index variable inside the name of the variable to be accessed.
  498.   Let's assume we need a 10 element array. We will call the array XYZ.
  499.   The elements will be XYZ1, XYZ2 through XYZ10. We may access the elements
  500.   by their explicit name or have an index variable to point to them. Our
  501.   index will be named XYZP and initialized to 1.
  502.   To assign a value to XYZ1 through XYZ10, enter the following lines:
  503.  
  504.     XYZP=1
  505.     while %XYZP < 11
  506.       XYZ%XYZP=something  ^ %XYZP is evaluated before "something" is assigned ^
  507.       compute XYZP=%XYZP + 1
  508.     endwhile
  509.  
  510.   To access the contents of the elements using an index, use the %{name}
  511.   construct as follows (see more details on this construct below):
  512.  
  513.     XYZP=1
  514.     while %XYZP < 11
  515.       echo %{XYZ%XYZP}  ^ %XYZP is evaluated before the outer % is evaluated ^
  516.       compute XYZP=%XYZP + 1
  517.     endwhile
  518.  
  519.  
  520.   If a shell file is active then the parameters to the shell may be accessed
  521.   by %1 through %9. More than 9 parameters may be passed to a shell program.
  522.   Parameters 10 and up will become accessible following shift.
  523.   Parameter %0 will return all the parameters as one string.
  524.   Parameter %# will return the number of parameters passed to the shell.
  525.   Parameter %! will return a single character from the keyboard.
  526.  
  527.     while '%1' != ''
  528.       echo %1 %2 %3
  529.       shift
  530.     endwhile
  531.  
  532.   The return code returned by application programs is accessed by %? variable.
  533.  
  534.     if %? != 0
  535.       echo program terminated abnormally
  536.       exit
  537.     endif
  538.  
  539.   The %! will return a single character from the keyboard.
  540.  
  541.     if '%!' == 'Y'
  542.       echo You just pressed the Y key.
  543.     else
  544.       You didn't press Y.
  545.     endif
  546.  
  547.   If the shell is executing a procedure, it can access up to 9 parameters
  548.   passed to the procedure following the procedure name on the calling line.
  549.   These parameters may be accessed with % followed by a dot followed by
  550.   a digit (1..9).
  551.  
  552.     call proc1 string1 string2 string3 "composite string"
  553.     .
  554.     .
  555.     procedure proc1
  556.     echo %.1 %.4
  557.     return
  558.  
  559.    output will be: string1 composite string
  560.  
  561.   Sh1 can take special actions in case a variable is defined or undefined.
  562.   The actions are:
  563.   %{var-string}   If var is undefined then return string.
  564.                   If var IS defined return var contents.
  565.   %{var=string}   If var is undefined then return string and also define var
  566.                   to equal to string. If var IS defined return var contents.
  567.   %{var?string}   If var is undefined then echo string to console and exit
  568.                   shell program.
  569.                   If var IS defined return var contents.
  570.   %{var+string}   If var is defined then return string else return nothing
  571.   %{var}          Same as %var only helps separate var from characters
  572.                   following the var name.
  573.  
  574.  
  575.   Finally, any other than the above characters preceded by % will be taken
  576.   literally.
  577.   Strings enclosed by " will not be expanded but if you put a % in front
  578.   of each " then the enclosed string will be expanded.
  579.  
  580.  
  581. Section 6. Using output of programs in command strings.
  582.  
  583.   A nice Unix feature is the ability to execute a program and incorporate
  584.   its output line into a command string. The way it works:
  585.   Enclose the program name and parameters in gravs ( ` ) where it makes the
  586.   most sense and watch it fly. Please note that only the first line of
  587.   the program's output will be used. Also notice that inside gravs, you
  588.   can pipe data between a few filters (see below).
  589.  
  590.     if '`cd`' == 'C:\'
  591.       echo currently at root directory of drive C:
  592.     endif
  593.  
  594.     WORDS=`type file | wc -w`
  595.  
  596.     SAVEDIR=`cd`
  597.     cd \anotherdir
  598.     .
  599.     .
  600.     cd %SAVEDIR
  601.  
  602.  
  603. Section 7. History of Commands buffer.
  604.  
  605.   The history buffer is 256 characters long. New commands push old commands
  606.   out if buffer is full. Commands three characters or less do not get logged
  607.   into the history buffer.
  608.  
  609.   7.1 The history mechanism may be invoked in one of two ways:
  610.     7.1.1 Enter "hist" followed by <return>
  611.     7.1.2 Press the Up arrow key
  612.  
  613.   7.2 Once the history mechanism is invoked, you may select one of the 
  614.     following actions:
  615.       7.2.1 Re-execute a command
  616.       7.2.2 Edit a command and then execute
  617.       7.2.3 Delete a command
  618.       7.2.4 Clear all commands
  619.  
  620.     Now, when you press up-arrow the system lists up to 24 of the latest 
  621.     commands to enter the queue.
  622.     It then positions the cursor on the last command. Use the up and
  623.     down arrows and Home and End to point to desired command.
  624.     Once the cursor points to the desired command, you may enter E to
  625.     edit it, D to delete it or <enter> to execute it as is.
  626.     You may also delete a few commands by repeatedly positioning the
  627.     cursor and hitting D. If the command being deleted is longer than
  628.     one line, the History mode will be exited. That is done due to the
  629.     fact that deleted lines' length cannot be determined for cursor
  630.     movement.
  631.     To clear the whole  buffer, press C.
  632.  
  633. Section 8. shx shell extention program.
  634.  
  635.   The shx utility may be used to add power to sh1 by combining it with the
  636.   above grav mechanism or by redirecting its output to a file and then reading
  637.   that file using the READ command and/or the FOR ... INFILE command.
  638.   Shx may also be called from command.com.
  639.  
  640.   shx functions and invocation format:
  641.  
  642.   shx -a[xX] string                  Parse and compute algebraic expression.
  643.     X and x will cause output to be in Hexadecimal format.
  644.     Examples:
  645.       shx -a "1 + 3 * ( 3 + 5 )"
  646.       shx -ax "xf0f0 + 22 - b101"    Note the x in front of f0f0 - hex number.
  647.                                      the b101 is a binary number 5.
  648.       shx -a %" %VAR1 + %VAR2 * 4 %" Quotes are preceeded by % to
  649.                                      allow sh1 to process inside of string.
  650.   shx -c[lwc] [filespec]             Count lines, words and/or characters in
  651.                                      file or if file name omitted then data
  652.                                      will be taken from standard input.
  653.  
  654.   shx -d[bdfmnpstz<digit>] filespecs...  Display filenames.
  655.     b  Replace the dots in filenames with a blank character (space).
  656.     d  Display only directories. d and f are mutually exclusive.
  657.     f  Display only files (no directories).
  658.     m  Display modification date in integer format. Truncates width to 2 columns.
  659.     n  Display name only (no size or <DIR>).
  660.     p  Eliminate path in files names if any ( C:\XXX\filename --> filename ).
  661.     s  Append summary to file listing. Prints number of files and directories.
  662.     t  Display modification date in string format. Truncates width to 1 column.
  663.     z  Return total size in bytes of all specified files.
  664.     <digit> Specify number of names per line. Default is 4.
  665.  
  666.   shx -fz filespec                   Display file size.
  667.   shx -m[dc] filespec  [filespec]    Display last modification date of file
  668.                                      or compare dates of 2 files [-mc].
  669.   shx -ms filespec datenumber        Set modification date of a file.
  670.  
  671.   shx -scrl filename [xl yt xr yb]   Load a file created with the -scrs option
  672.                                      to the screen with optional window 
  673.                                      definition.
  674.   shx -scrs filename [xl yt xr yb]   Save screen in a file. The optional params
  675.                                      define a window to be saved instead of the
  676.                                      whole screen.
  677.   shx -scrt filename                 Paint up to 25 lines from a regular text 
  678.                                      file. Screen attribute is set to all 7's.
  679.   shx -sd string position length     Delete characters from string.
  680.   shx -si string substring position  Insert substring at position.
  681.   shx -sl string                     Return length of string.
  682.   shx -so string substring position  Overlay substring on top of string starting
  683.                                      at given position.
  684.   shx -sp string substring           Return position of substring in string
  685.                                      or 0.
  686.   shx -sr string substring           Remove substring from string.
  687.   shx -ss string position length     Return subtring from position and of
  688.                                      length.
  689.   shx -su string                     Return string in uppercase.
  690.   shx -sw string wordnumber          Return a specified word of string.
  691.   shx -t[d]                          Display system time as an integer or
  692.                                      a string [-td].
  693.   shx -vr                            Display shx version number.
  694.   shx -wd outfile filespecs...       Write all filenames to outfile.
  695.   shx -xt filespec line-number       Extract line from file.
  696.   shx -zb filespec                   Create a file with zero bytes in it.
  697.  
  698.  
  699. Section 9. Shell files.
  700.  
  701.   Shell files have a .sh extension to avoid conflict with command.com's
  702.   .BAT files.
  703.  
  704.   Comments inside shell files are enclosed by carets ( ^ ).
  705.   Multiple-line comments are allowed.
  706.  
  707.     echo something ^this is a comment^
  708.  
  709.   Please feel free to put as many comments as necessary since they are
  710.   removed upon loading of the shell file and thus do not take up space.
  711.   You can put a comment in the middle of a command.
  712.  
  713.     copy %SRC ^get files from \somedir ^ %DST ^ and put into \anotherdir ^
  714.  
  715.   If you need a ^ as part of the text then preceed it with a %.
  716.  
  717.   Leading spaces are eliminated while loading a shell file so please
  718.   use leading spaces freely to make shell files more readable and
  719.   maintaineable.
  720.  
  721.   Included are a few sample shell files. Please take a look at them
  722.   to get a better idea of sh1 shell programming.
  723.  
  724.   Shells may be debugged by entering the following command before 
  725.   executing the shells:
  726.  
  727.     debug +
  728.  
  729.   Once the shell is invoked, each line of shell will be displayed and
  730.   a debug prompt "dbg> " will appear.  Pressing return will cause
  731.   execution of that line. Please note that grav enclosed commands will
  732.   be executed before line is displayed.
  733.   A few one-letter debug commands are available at the debug prompt:
  734.  
  735.     1. O or o   display (O)riginal line ( before translation ).
  736.  
  737.     2. E or e   (E)dit translated line before it is executed.
  738.  
  739.     3. I or i   (I)nsert and execute a line before current line.
  740.  
  741.     4. S or s   (S)how status. Execute the SHOWSTAT command.
  742.  
  743.     5. X or x   e(X)amine an environment variable and change if desired.
  744.  
  745.     6. B or b   Insert a (B)reakpoint in current shell.
  746.                 Sh1 will display a question mark and the first line
  747.                 of the shell. Pressing the space bar will show the next
  748.                 lines of the shell. Once you reach the desired line,
  749.                 press return to indicate your choice. You may quit by
  750.                 pressing the escape key.
  751.  
  752.     8. L or l   Insert breakpoint at this line and (L)oop around to it.
  753.                 This command is useful for looping around any loop
  754.                 construct and stopping at the same spot.
  755.  
  756.     9. D or d   Open a window to DOS. If the command is followed by a
  757.                 string, that string will be executed and then wait for
  758.                 a key to be pressed before returning to the debugger.
  759.                 If the D alone is entered, a new copy of sh1 will be
  760.                 loaded and allow you to execute any commands you may
  761.                 desire. To return to debugger, enter EXITSH1 <return>.
  762.  
  763.    10. C or c   (C)ontinue execution of the shell without stopping.
  764.                 The C command will cause the debugger to be disabled.
  765.                 To debug again, enter the DEBUG command after the shell
  766.                 finishes execution.
  767.  
  768.    11. H or h   The (H)elp will attempt to execute the command
  769.                   LIST SH1.DOC
  770.                 under a new copy of Sh1. If you don't have a listing utility
  771.                 by the name of LIST you can create a shell called LIST.SH
  772.                 which will invoke the listing utility you DO have.
  773.                 Once you exit the listing utility, any key pressed will cause
  774.                 the system to restore the debug screen.
  775.  
  776.    12. Q or q   (Q)uit shell execution.
  777.  
  778.    13. P or p   Break on (P)rocedure name. Sh1 will execute at full speed
  779.                 until it encounters a call to the given procedure. This
  780.                 breakpoint will remain active until an empty p command is
  781.                 entered. The procedure name should follow the P with  no
  782.                 separating spaces. If the debug mode is off but the breakpoint
  783.                 is active, the debug mode will be automatically enabled upon
  784.                 reaching a procedure defined by P.
  785.  
  786.    14. R or r   Break on (R)eturn from procedure. The R command takes no
  787.                 parameters. It will cause a breakpoint on the first return 
  788.                 from any procedure. It will cause Sh1 to run at full
  789.                 speed until after a return is executed.
  790.  
  791.    15. V or v   (V)iew full output screen. The V command will cause the debug
  792.                 lines to dissappear so you can see the full output screen.
  793.                 To return to debug, press any key.
  794.  
  795.   The X command should be followed with a variable name:
  796.  
  797.     xSH1PROMPT
  798.  
  799.   Once debug is finished, enter the following command to disable the
  800.   debug feature:
  801.  
  802.     debug -
  803.  
  804.   NOTES:
  805.    1. After sh1 is loaded it checks for the presence of a shell file
  806.       named "sh1init.sh". If present, this shell file is executed
  807.       automatically the same way AUTOEXEC.BAT is executed by command.com.
  808.       Sh1 does not look for sh1init.sh if it is invoked with command line
  809.       parameters.
  810.  
  811.    2. The total active shell runtime space is limited to 64K bytes.
  812.       If you need HUGE shells, break them down to a main shell that
  813.       will invoke sub-shells. You will discover that most shells take up
  814.       very little room anyway. To see actual size of loaded shell, insert
  815.       in that shell a SHOWSTAT command or execute the shell after turning
  816.       the debug mode on and then enter the "s" debug command.
  817.       The "shell size" indicates how many bytes of shell are currently loaded.
  818.  
  819. Section 10. Compiling shell files.
  820.  
  821.   Sh1 recognizes a type shell files with a suffix of .SHC which stands
  822.   for compiled shell. Once you have a working shell, you may use the
  823.   SHC.EXE to tokenize the shell and and save it under the same name but 
  824.   with the new suffix .SHC. Most of the keywords are translated to a one 
  825.   byte code and all leading spaces are deleted.
  826.   The advantages of compiling (or tokenizing) the shell file are:
  827.    - Tokenized files are smaller, thus are loaded faster and cause fewer
  828.      shell page swaps (transparent to the user but takes time).
  829.    - Execution time improves by up to 70% depending on what the shell does.
  830.  
  831.   SHC.EXE outputs to standard output device so to save the output you have 
  832.   to use the ">" redirection operator:
  833.  
  834.     SHC eds.sh > eds.shc
  835.  
  836.   NOTE:
  837.    Sh1 allows normal debugging of compiled shells by expanding the tokenized
  838.    lines while in debug mode.
  839.  
  840.  
  841. Section 11. Defining the prompt and sh1 temporary file directory.
  842.  
  843.  11.1 SH1PROMPT
  844.  
  845.   The default sh1 prompt is "sh1>". Not very informative, hah?
  846.   Well... sh1 has the same mechanism as command.com for defining
  847.   a prompt string. The environment variable SH1PROMPT is used to contain
  848.   that definition. Special escape sequences in the prompt are entered as
  849.   a Dollar sign followed by a single character.
  850.   Notice that the variable name has changed from PROMPT to SH1PROMPT to
  851.   avoid conflict with command.com.
  852.   The following list shows all the escape sequences currently implemented 
  853.   in sh1:
  854.  
  855.     $$          Output the Dollar sign
  856.     $d          Output the current disk drive name
  857.     $p          Output the current directory path
  858.     $g          Output >
  859.     $l          Output <
  860.     $b          Output |
  861.     $c          Clear screen
  862.     $n          Output <cr><lf>
  863.     $r          Output <cr>
  864.     $t          Output a tab
  865.  
  866.   Examples:
  867.  
  868.     SH1PROMPT=$d$p$g
  869.  
  870.     SH1PROMPT=$c$n$n$nNext?
  871.  
  872.   You can initialize the prompt in the sh1init.sh mentioned above.
  873.  
  874.  11.2 SH1FILES
  875.  
  876.   The sh1 system uses some temporary data files. If you have a
  877.   Ram-disk and you would like sh1 to put these files there,
  878.   add a line to your sh1init.sh:
  879.  
  880.     SH1FILES=<subdir>
  881.  
  882.   If you do not specify SH1FILES, the default is the root directory
  883.   of the currently selected disk drive.
  884.  
  885.  
  886. Section 12. Bugs and other funny phenomena.
  887.  
  888.   For some weird reason, the JET utility of Tall Tree Systems will
  889.   not work properly if the JET command line is not terminated with
  890.   I/O redirection.
  891.   To use JET enter:
  892.  
  893.     JET src dst params> con:
  894.  
  895.   ANSI.SYS, if loaded, causes the grav mechanism to always return an
  896.   empty string.
  897.  
  898.  
  899. ----------------------------------------------------------------------------
  900.  
  901. Appendix A - History of changes up to V1.08A inclusive.
  902.  
  903.   2.0 Only commands of more than 3 characters get logged in history queue.
  904.  
  905.   2.1 Ver 1.01 sh1 allowed alphabetic variable names ONLY.
  906.       Ver 1.02 is fixed to allow digits in names.
  907.  
  908.   2.2 If and While statements with long strings caused system to hang. Fixed.
  909.  
  910.   2.3 Commands with I/O redirection or piping got logged twice into the
  911.       history file. Fixed.
  912.  
  913.   2.4 Multiple-line echo statements can now be written or appended to a file
  914.       by putting > or >> respectively after closing exclamation point.
  915.  
  916.   2.5 The variable %0 returns all parameters passed to a shell chained
  917.       together.
  918.  
  919.   2.6 Showstat command can be made to display sh1 version by adding a "v"
  920.       switch.   Ex. showstat v <cr>
  921.  
  922.   2.7 History manipulation:
  923.      Pressing Down arrow enters history mode without displaying the
  924.      recorded command lines.
  925.  
  926.   2.8 The HELP command has been removed to conserve space.
  927.  
  928.   2.9 The shx -d option has been expanded to allow finer control of output.
  929.       See shx description below.
  930.  
  931.   2.10 Starting with V1.04, and ELSE statement can be followed with an IF
  932.       for forming the construct IF ... ELSE IF ... ELSE IF ... ELSE ... ENDIF
  933.  
  934.   2.11 V1.04 - "shx -sr" added for removing a substring from a string.
  935.       This can be convenient if you know that a string contains a certain
  936.       substring which you want to remove. If substring is not found then
  937.       the whole string is returned.
  938.  
  939.   2.12 V1.05 modifications:
  940.  
  941.    2.12.1 History mechanism completely changed. Now, when you press up-arrow
  942.           the system lists up to 24 of the latest commands to enter the queue.
  943.           It then positions the cursor on the last command. Use the up and
  944.           down arrows and Home and End to point to desired command.
  945.           Once the cursor points to the desired command, you may enter E to
  946.           edit it, D to delete it or <enter> to execute it as is.
  947.           You may also delete a few commands by repeatedly positioning the
  948.           cursor and hitting D. If the command being deleted is longer than
  949.           one line, the History mode will be exited. That is done due to the
  950.           fact that deleted lines' length cannot be determined for cursor
  951.           movement.
  952.           To clear the whole  buffer, press C.
  953.           The down arrow entry into History has been disabled.
  954.           I took out the load/save features to minimize sh1 size. If many
  955.           people will be angry, I will put it back in.
  956.  
  957.    2.12.2 A few special variables were added. See the section on variables.
  958.  
  959.    2.12.3 Regular command.com batch files are now recognized and executed
  960.           in addition to the shell files. If you have an extensive collection
  961.           of batch files, you don't have to modify them to shells.
  962.  
  963.    2.12.4 Fixed compute command to handle signed long integers.
  964.  
  965.    2.12.5 Changed the line editing to jump to words delimited by non-
  966.           Alphanumeric characters instead of only space.
  967.  
  968.   2.13 V1.06
  969.  
  970.        Oops, v1.05 had a little cosmetic bug in the history mechanism.
  971.        The first time the history was invoked after entering a new command,
  972.        an extra blank line appeared on line 24. V1.06 fixes this one tiny
  973.        problem.
  974.  
  975.   2.14 V1.07
  976.  
  977.        Fixed another tiny bug in the CALL command.
  978.        EXIT command now has an optional return value.
  979.        Shx has new file listing options (b,p).
  980.        Sh1 can now be called with command line parameters for single
  981.        shell execution (e.g.  sh1 <shell-name> <parameters>...).
  982.        Exitsh1 can be executed from within a shell and may specify
  983.        ERRORLEVEL code.
  984.        Shx -c option (count lines/words/chars) can now also operate
  985.        as a filter.
  986.        Sh1 did not execute pipes within gravs correctly. Fixed.
  987.  
  988.   2.15 V1.08
  989.  
  990.        A one-line echo following a multi-line echo would crash sh1. Fixed.
  991.        Condition statements can contain multiple tests now.
  992.        Arithmetic/logic Expressions are fully algebraic including 
  993.        parentheses.
  994.        A new shell debug facility has been added (See section 9).
  995.        Maximum shell size has been increased to 64K bytes.
  996.        Case statements may now have multiple cases per block.
  997.        The ACCEPT statement has an optional -e switch for editing the
  998.        contents of a variable instead of just filling it with a new string.
  999.        A new special variable %! returns a single character from keyboard.
  1000.        The ECHO statement will omit the newline character if last character
  1001.        is an underline ( cursor will stay to right of string ).
  1002.        NEW commands:
  1003.         REPEAT ... UNTIL <expr>
  1004.         FOR <var> IN <list> ... ENDFOR
  1005.         FOR <var> INFILE <textfile> ... ENDFOR
  1006.        The READ command has been enhanced to be able to get the next word
  1007.        from the FOR list (READ f <destvar>).
  1008.        Shx -zb option added for creating empty files.
  1009.        Shx has two new file listing options (t,m) for displaying file
  1010.        modification date.
  1011.        Shx has two new options for saving the screen to a file and painting
  1012.        the screen from a file ( -scrs and -scrl respectively ).
  1013.  
  1014.   2.16 V1.08A
  1015.  
  1016.        Fixed a bug found in V1.08 which caused sh1 to get confused if it
  1017.        saw a " in the parameter list of a shell.
  1018.        A new command has been added to allow local variables in shells
  1019.        (see LOCAL command).
  1020.  
  1021.  
  1022. ----------------------------------------------------------------------------
  1023.  
  1024. Appendix B - Shx usage examples.
  1025.  
  1026.   The enclosed shell files contain many examples of shx usage. Please take
  1027.   a look at them. The Shx is mainly used in conjunction with the grav
  1028.   mechanism of Sh1. Most of its options cause shx to output a single line
  1029.   to standard output (the exceptions are the -wd, -d, -ms, -scrl, -scrs,
  1030.   -scrt and -zb options which do not send anything to standard output).
  1031.  
  1032.  Example 1 - Get total size of all files in this directory with a prefix of
  1033.              .COM and subtract it from total size of files ending with .EXE.
  1034.              Echo the difference.
  1035.  
  1036.         compute DIFF=`shx -dz *.exe` - `shx -dz *.com`
  1037.         echo %DIFF
  1038.  
  1039.  Example 2 - Compile a "C" program only if source is more recent than its
  1040.              object file. The -mc option returns the number of seconds
  1041.              of difference between the modification date/time of the two
  1042.              files.
  1043.  
  1044.         if `shx -mc program.c program.obj` >= 0
  1045.           msc program;
  1046.         endif
  1047.  
  1048.  Example 3 - Extract the third word of the fifth line of a text file.
  1049.  
  1050.         LINE=`shx -xt file 5`
  1051.         WORD=`shx -sw %"%LINE%" 3`
  1052.         echo '%WORD' is the 3rd word in '%LINE'
  1053.  
  1054.  Example 4 - Add the numeric values of two variables and get sum in
  1055.              hexadecimal format with leading 0 and trailing H.
  1056.  
  1057.         SUM=`shx -aX %"%VAR1 + %VAR2%"`
  1058.         echo %VAR1 + %VAR2 = 0%{SUM}H
  1059.  
  1060.      The same result canbe obtained from a single more complicated line:
  1061.  
  1062.         echo %VAR1 + %VAR2 = 0`shx -aX %"%VAR1 + %VAR2%"`H
  1063.