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 >
Wrap
Text File
|
1987-10-26
|
43KB
|
1,063 lines
Sh1 Documentation Version 1.11 Date 10-23-87
Table of contents
------------------
Disclaimer, Trademarks, my name and address etc. . . . . Section 0
Description. . . . . . . . . . . . . . . . . . . . . . . Section 1
History of changes and bug fixes . . . . . . . . . . . . Section 2
The commands that are built into sh1 . . . . . . . . . . Section 3
Algebraic and Logical Expression Format (in BNF) . . . . Section 4
Variables and their uses . . . . . . . . . . . . . . . . Section 5
Using output of programs in command strings. . . . . . . Section 6
History of Commands buffer . . . . . . . . . . . . . . . Section 7
shx shell extention program. . . . . . . . . . . . . . . Section 8
Shell files. . . . . . . . . . . . . . . . . . . . . . . Section 9
Compiling shell files. . . . . . . . . . . . . . . . . . Section 10
Defining the prompt and sh1 temporary file directory . . Section 11
Bugs and other funny phenomena . . . . . . . . . . . . . Section 12
History of changes up to V1.08A inclusive. . . . . . . . Appendix A
Shx usage examples . . . . . . . . . . . . . . . . . . . Appendix B
Section 0. Disclaimer, Trademarks, my name and address etc.
I make no representation or warranties with respect to the
contents hereof and specifically disclaim any implied warranties
to the suitability of this program for any particular purpose.
You must determine that yourself. In addition, you should
understand that using a program of this type on an IBM PC or
compatible has inherent risks and that you may inadvertently
damage or destroy valuable programs or data. I expressly
decline to assume liability for any use of this program by you,
and your use of this program constitutes your agreement to hold
me blameless.
BUT if someone finds a bug and goes to the trouble of telling me,
I would be more than happy to fix it and upload an update.
I also welcome any other comments and suggestions.
MS-DOS is a registered trademark of Microsoft Corporation.
PC-DOS is a registered trademark of IBM Corporation.
IBM PC is a registered trademark of IBM Corporation.
If you find this program to be of benefit to you, please send any
contribution ($10 suggested) to me so I can spend more time on
improving this program and writing other such programs.
Thanks...
Noam Naaman
406 Prospect Ave #4K
Hackensack, NJ 07601
(201) 343-7242
You may leave me a message on one of these fine bulletin board
systems (all operating at 2400 Baud, 8 bits, no parity):
The Right Choice (201) 974-8317
CloneWorld (201) 290-1183
BOSS (201) 568-7293
Section 1. Description
Sh1 is a shell program written out of frustration of having
to deal with MS(PC)-DOS command.com's idiotic interface.
I tried to implement as many features of Unix as time permitted.
Some of the enhancements of this shell over command.com are:
1.1. Environment variables can actually be of use.
1.2. Batch files can be nested to a depth of 8 ( Hurray!!!)
1.3. History of commands:
1.3.1 Re-execute a command
1.3.2 Edit a command
1.3.3 Delete a command
1.3.4 Clear all commands
1.4. Batch files (shell files a la Unix) can pipe output of one program
into a command line (e.g. SAVEPATH=`cd` will assign the current dir
to an environment variable by the name of SAVEPATH )
1.5. "while", "case" and "if else endif" constructs are implemented and
may be nested.
1.6. Procedures may be defined and called.
1.7. An accompanying utility "shx.exe" extends the proramability of sh1
even further. Functions of shx.exe are:
1.7.1 String handling: substring extraction, position, delete, insert
1.7.2 Return size of file
1.7.3 Create file containing an expanded list of wildcard parameters
Sh1 searches for an executable file in the following order:
- .COM and .EXE files.
- .SHC compiled shells (See section 10).
- .SH regular shells (See section 9).
Section 2. History of changes and bug fixes.
In order to make this section more "enjoyable", info on versions up to
1.08A inclusive, has been moved to Appendix A.
2.17 V1.09
Version 1.08A had a bug creap in which would crash the system on default
disk change. FIXED.
Added two new options to shx:
shx -ms allows setting the modification date of a file.
shx -so allows overlaying one string over another.
2.17 V1.10
Sh1 recognizes a new type shell files with a suffix of .SHC which stands
for compiled shell. Once you have a working shell, you may use the new
SHC.EXE to tokenize the shell and and save it under the same name but
with the new suffix .SHC. Most of the keywords are translated to a one
byte code and all leading spaces are deleted. See section 10 for more
details.
The gotoxy command has been enhanced to accept two full algebraic
expressions separated by a space.
A new unary NOT operator has been added to algebraic expressions. The
NOT operator is the ! character.
Procedures may now get up to 9 parameters. See CALL description and
section 5.
2.18 V1.11
One-dimensional arrays may be created and referenced (See section 5).
New debugging commands: break on procedure name and break on return,
view whole application output screen (p, r and v respectively).
Shx has a new option -scrt for painting the screen from a regular
text file instead of a file created with the -scrs option.
The ACCEPT command returns a code in the %? variable that indicates
which key was pressed to exit the line editing.
The return codes are:
13 for [Return]
27 for [Esc]
72 for Up arrow
73 for PgUp
80 for Down arrow
81 for PgDn
A new appendix B has been added, showing some ways of using Shx.
Section 3. The commands that are built into sh1
(note: commands preceded by * may be executed only in a shell file )
3.1 ACCEPT Accept a string from keyboard and store in an environment
variable. If a -e is inserted between the ACCEPT and the
variable name, the contents of the variable will be
displayed and edited.
accept GETSTRING
accept -e REEDIT
ACCEPT returns a code which may be accessed with the %?
special variable. This code will tell which key caused
the ACCEPT to exit editing. The return codes are:
13 for [Return]
27 for [Esc]
72 for Up arrow
73 for PgUp
80 for Down arrow
81 for PgDn
3.2 *BREAK Break out of case block or loop. The BREAK will cause
the shell to continue execution at the first statement
following a CASE, REPEAT-UNTIL, WHILE or FOR block it
is currently in. A break statement will exit only
one block level.
3.3 *CALL Call procedure with optional parameters. Up to 9 Parameters
may follow the procedure name on the calling line.
Procedure name is case sensitive.
*RETURN Return from procedure.
*PROCEDURE Procedure declaration.
call ABC substring
echo %RETSTRING
exit
procedure ABC
RETSTRING=return this string with addition of %.1
return
On return, RETSTRING=return this string with addition of substring
3.4 *CASE The parameter following the CASE stmt is compared to
*ENDCASE case specifiers enclosed by endcase command.
Each specifier is a string terminated with *) .
default*) if given will be chosen if none of the preceding
specifiers were chosen. You may specify multiple cases per
line but you may not group the default*) with any other
case.
case %STR
1*)
echo STR = 1
break
2*)
echo STR = 2
break
3*) 4*) 5*)
echo STR = 3 thru 5
break
default*)
echo STR is either > 5 or < 1
break
endcase
3.5 CHDIR Same as command.com
CD
3.6 CLEOL Clear to end of line.
3.7 CLOSE Close any file opened by OPEN command.
close 1 closes file #1
close * closes all open files
3.8 CLS Same as command.com
3.9 COMPUTE Do arithmetic operations on environment variables containing
numeric strings.
compute ACC=%ACC + `shx -fz filename`
compute ACC=%ACC - %SECONDVAR
compute ACC=%ACC * 10 + 5
compute ACC=(%ACC / (%B + 2)) | 128
3.10 COPY Same as command.com
3.11 DATE Same as command.com
3.12 DEBUG Debug command execution in shell files. Debug may be followed
with a '+' to turn debug on, '-' to turn debug off or nothing
to cause debug flag to toggle. Please see section 9 for more
details on debugging.
debug +
debug -
debug
3.13 DEL Same as command.com
3.14 DIR Same as command.com
3.15 ECHO Echo may work as in command.com or as a block echo
using ! as delimiter. The echo may be redirected to a file
by adding > or >> and a file name after closing exclamation
point. Each echo is limited to 2000 characters.
The keywords IF, WHILE and REPEAT should not be put as the
first words in any of the multiline echo lines to avoid
confusing sh1.
If you wish to cause the cursor to stay to the right of
the string, put an underline as last character on echo line.
echo this string will be printed on screen followed by a newline.
echo this string will be printed on screen without newline_
echo !
This is a multi-line echo string.
In case the closing ! is followed by > filename then this text will
be written to filename.
In case the closing ! is followed by >> filename then this text will
be appended to filename.
!
3.16 ERASE Same as command.com
3.17 *EXIT Exit from shell execution. Optional numeric value may
follow. The calling shell can access this return value with
the %? special variable.
exit %R Exit current shell and return the value currently in
the R variable.
3.18 EXITSH1 Exit back to good ol' command.com.
Sh1 will return ERRORLEVEL 0 as default but if exitsh1 is
followed by number, sh1 will return that number.
exitsh1
3.19 *FOR A For loop will expand a list of filenames and assign each
*ENDFOR element of the list to the specified variable. As long as
the list is not exhausted, the commands between the FOR
and ENDFOR will be executed. A second variation on the FOR
command is the INFILE which takes its arguments from a
pre-existing text file.
In this version, FOR commands CANNOT BE NESTED.
Sh1 MUST have access to SHX.EXE for this command to work.
The syntax is:
FOR <var> IN <list>
FOR <var> INFILE <textfile>
for XX in *.C *.bak Will expand the wildcard specifications.
echo %XX
endfor
for XX infile FLNAMES.TXT Will read words from FLNAMES.TXT files.
echo %XX
endfor
3.20 GOTOXY Positions cursor on screen.
Followed by two algebraic expressions. The first expression
gives the value of X while the second gives the value of Y.
gotoxy 1 1
gotoxy %VARX+2 2*%VARY-5
3.21 HIST Access history of commands. Can also be invoked by
pressing the Up arrow.
3.22 *IF If statements may compare two strings, two numbers,
*ELSE test if a file exists or check for pending keyboard input.
*ENDIF See expression format below.
*ELSE IF The else-if construct can be repeated as often as desired.
if %COUNT < 10 + %UPPERLIMIT
compute COUNT=%COUNT + 1
else if %COUNT > 20 & %COUNT < 40
compute COUNT=%COUNT - 2
else
echo COUNT is equal to or greater than 10 and less than 21
endif
3.23 LOCAL Defines environment variables as local to the current shell
and shell which are called by the current shell. On exiting
the current shell, all variables appearing on this line,
will be removed from environment. This line should be the
first executable line of the shell. Only one LOCAL line per
shell is allowed.
Please note that there can be only one variable of the same
name in the environment. If one shell calls another and the
called shell removes a variable used by the calling shell,
that variable will be lost to the calling shell.
local ThisVar ThatVar TheOtherVar
3.24 MKDIR Same as command.com
MD
3.25 OPEN Open up to eight files for I/O mode as in the C language.
open 1 filename r Open file for reading
open 2 filename w Open file for writing
open 3 filename a Open file for writing, append text at eof
open 1 filename r+ Open file for read/write, file must exist
open 4 filename w+ Open file for read/write, create if DNE
open 4 filename a+ Open file for read/append, create if DNE
3.26 READ Read from an opened file a line of text and store in an
environment variable.
read 1 INLINE Will read from file #1
read f WORD Will read the next word from the FOR list if
a FOR loop is currently active.
3.27 REN Same as command.com
3.28 RMDIR Same as command.com
RD
3.29 SET Set shows the currently defined environment variables.
It is an internal command of sh1. If you pipe its
output to a file, you will in actuality be executing
the COMMAND.COM set command which, in addition
to the variables, will show some hidden environment
strings such as ;C_FILE_INFO and a few "not used".
3.30 *SHIFT Same as command.com
3.31 SHOWSTAT Show status of system. May be embedded in shell files for
debugging purposes.
3.32 TIME Same as command.com
3.33 TRACE Trace command execution in shell files. Trace may be followed
with a '+' to turn trace on, '-' to turn trace off or nothing
to cause trace flag to toggle.
trace +
trace -
trace
3.34 TYPE Same as command.com
3.35 *WHILE While loops will execute enclosed commands as long as
*ENDWHILE expression returns TRUE. See expression format below.
COUNT=1
while %COUNT < 10
compute COUNT=%COUNT+1
gotoxy 30 10
echo %COUNT
endwhile
3.36 *REPEAT The Repeat loop is the opposite of the While loop in that
*UNTIL it checks for loop repeat at the end of the loop.
N=1
repeat
echo %N
compute N=%N+1
until %N > 20
3.37 WRITE Write a string into an open file.
write 2 %OUTLINE
write 2 put this string into file 2
Section 4. Algebraic and Logical Expression Format (in BNF)
<expr> ::= <expr0>
<expr0> | <expr0> ( Or )
<expr0> & <expr0> ( And )
<expr0> ::= <expr1>
<expr1> <relational operator> <expr1>
<expr1> ::= <expr2>
<expr2> + <expr2>
<expr2> - <expr2>
<expr2> ::= <expr3>
<expr3> * <expr3>
<expr3> / <expr3>
<expr3> ::= <number>
'string' <relational operator> 'string'
( <expr> )
! <expr> Unary NOT operator
-f <filename> test for existance of file
-k test for keyboard input
<number> ::= <digits>
-<digits>
<digits> ::= <digit>
<digits><digit>
<relational operator> may be == != >= <= > <
Examples:
%VAR == 10
%VAR1 < %VAR2
%VAR2 + 5 * %VAR1
'%PATH' != '`cd`'
-f sh1.exe test for presence of file
! -f sh1.exe test for absence of file
-k test for keyboard input
Comparisons may be combined to form a more complicated test.
The two operators & (and) and | (or) separate between comparisons:
%1 < %R & %2 > %S
'%1' == '%STR' | %2 < %NUM
Compute commands assign a value to a variable by evaluating an
algebraic expression which may also include comparisons. Any
comparison yields either a "-1" if true or "0" if false:
compute N = (1 > 2) * 20 will assign the value 0 to N.
compute N = (1 < 2) * 20 will assign the value 20 to N.
Section 5. Variables and their uses.
Any environment variable may be assigned a string by simply typing
the variable's name followed by = followed by any string:
DUMMYVAR=dummy string
The contents of a variable may be accessed by preceding the variable name
with %.
echo %PATH
PATH=%PATH;c:\anotherdir
Creating and accesssing one-dimentional arrays of variables is accomplished
by using an index variable inside the name of the variable to be accessed.
Let's assume we need a 10 element array. We will call the array XYZ.
The elements will be XYZ1, XYZ2 through XYZ10. We may access the elements
by their explicit name or have an index variable to point to them. Our
index will be named XYZP and initialized to 1.
To assign a value to XYZ1 through XYZ10, enter the following lines:
XYZP=1
while %XYZP < 11
XYZ%XYZP=something ^ %XYZP is evaluated before "something" is assigned ^
compute XYZP=%XYZP + 1
endwhile
To access the contents of the elements using an index, use the %{name}
construct as follows (see more details on this construct below):
XYZP=1
while %XYZP < 11
echo %{XYZ%XYZP} ^ %XYZP is evaluated before the outer % is evaluated ^
compute XYZP=%XYZP + 1
endwhile
If a shell file is active then the parameters to the shell may be accessed
by %1 through %9. More than 9 parameters may be passed to a shell program.
Parameters 10 and up will become accessible following shift.
Parameter %0 will return all the parameters as one string.
Parameter %# will return the number of parameters passed to the shell.
Parameter %! will return a single character from the keyboard.
while '%1' != ''
echo %1 %2 %3
shift
endwhile
The return code returned by application programs is accessed by %? variable.
if %? != 0
echo program terminated abnormally
exit
endif
The %! will return a single character from the keyboard.
if '%!' == 'Y'
echo You just pressed the Y key.
else
You didn't press Y.
endif
If the shell is executing a procedure, it can access up to 9 parameters
passed to the procedure following the procedure name on the calling line.
These parameters may be accessed with % followed by a dot followed by
a digit (1..9).
call proc1 string1 string2 string3 "composite string"
.
.
procedure proc1
echo %.1 %.4
return
output will be: string1 composite string
Sh1 can take special actions in case a variable is defined or undefined.
The actions are:
%{var-string} If var is undefined then return string.
If var IS defined return var contents.
%{var=string} If var is undefined then return string and also define var
to equal to string. If var IS defined return var contents.
%{var?string} If var is undefined then echo string to console and exit
shell program.
If var IS defined return var contents.
%{var+string} If var is defined then return string else return nothing
%{var} Same as %var only helps separate var from characters
following the var name.
Finally, any other than the above characters preceded by % will be taken
literally.
Strings enclosed by " will not be expanded but if you put a % in front
of each " then the enclosed string will be expanded.
Section 6. Using output of programs in command strings.
A nice Unix feature is the ability to execute a program and incorporate
its output line into a command string. The way it works:
Enclose the program name and parameters in gravs ( ` ) where it makes the
most sense and watch it fly. Please note that only the first line of
the program's output will be used. Also notice that inside gravs, you
can pipe data between a few filters (see below).
if '`cd`' == 'C:\'
echo currently at root directory of drive C:
endif
WORDS=`type file | wc -w`
SAVEDIR=`cd`
cd \anotherdir
.
.
cd %SAVEDIR
Section 7. History of Commands buffer.
The history buffer is 256 characters long. New commands push old commands
out if buffer is full. Commands three characters or less do not get logged
into the history buffer.
7.1 The history mechanism may be invoked in one of two ways:
7.1.1 Enter "hist" followed by <return>
7.1.2 Press the Up arrow key
7.2 Once the history mechanism is invoked, you may select one of the
following actions:
7.2.1 Re-execute a command
7.2.2 Edit a command and then execute
7.2.3 Delete a command
7.2.4 Clear all commands
Now, when you press up-arrow the system lists up to 24 of the latest
commands to enter the queue.
It then positions the cursor on the last command. Use the up and
down arrows and Home and End to point to desired command.
Once the cursor points to the desired command, you may enter E to
edit it, D to delete it or <enter> to execute it as is.
You may also delete a few commands by repeatedly positioning the
cursor and hitting D. If the command being deleted is longer than
one line, the History mode will be exited. That is done due to the
fact that deleted lines' length cannot be determined for cursor
movement.
To clear the whole buffer, press C.
Section 8. shx shell extention program.
The shx utility may be used to add power to sh1 by combining it with the
above grav mechanism or by redirecting its output to a file and then reading
that file using the READ command and/or the FOR ... INFILE command.
Shx may also be called from command.com.
shx functions and invocation format:
shx -a[xX] string Parse and compute algebraic expression.
X and x will cause output to be in Hexadecimal format.
Examples:
shx -a "1 + 3 * ( 3 + 5 )"
shx -ax "xf0f0 + 22 - b101" Note the x in front of f0f0 - hex number.
the b101 is a binary number 5.
shx -a %" %VAR1 + %VAR2 * 4 %" Quotes are preceeded by % to
allow sh1 to process inside of string.
shx -c[lwc] [filespec] Count lines, words and/or characters in
file or if file name omitted then data
will be taken from standard input.
shx -d[bdfmnpstz<digit>] filespecs... Display filenames.
b Replace the dots in filenames with a blank character (space).
d Display only directories. d and f are mutually exclusive.
f Display only files (no directories).
m Display modification date in integer format. Truncates width to 2 columns.
n Display name only (no size or <DIR>).
p Eliminate path in files names if any ( C:\XXX\filename --> filename ).
s Append summary to file listing. Prints number of files and directories.
t Display modification date in string format. Truncates width to 1 column.
z Return total size in bytes of all specified files.
<digit> Specify number of names per line. Default is 4.
shx -fz filespec Display file size.
shx -m[dc] filespec [filespec] Display last modification date of file
or compare dates of 2 files [-mc].
shx -ms filespec datenumber Set modification date of a file.
shx -scrl filename [xl yt xr yb] Load a file created with the -scrs option
to the screen with optional window
definition.
shx -scrs filename [xl yt xr yb] Save screen in a file. The optional params
define a window to be saved instead of the
whole screen.
shx -scrt filename Paint up to 25 lines from a regular text
file. Screen attribute is set to all 7's.
shx -sd string position length Delete characters from string.
shx -si string substring position Insert substring at position.
shx -sl string Return length of string.
shx -so string substring position Overlay substring on top of string starting
at given position.
shx -sp string substring Return position of substring in string
or 0.
shx -sr string substring Remove substring from string.
shx -ss string position length Return subtring from position and of
length.
shx -su string Return string in uppercase.
shx -sw string wordnumber Return a specified word of string.
shx -t[d] Display system time as an integer or
a string [-td].
shx -vr Display shx version number.
shx -wd outfile filespecs... Write all filenames to outfile.
shx -xt filespec line-number Extract line from file.
shx -zb filespec Create a file with zero bytes in it.
Section 9. Shell files.
Shell files have a .sh extension to avoid conflict with command.com's
.BAT files.
Comments inside shell files are enclosed by carets ( ^ ).
Multiple-line comments are allowed.
echo something ^this is a comment^
Please feel free to put as many comments as necessary since they are
removed upon loading of the shell file and thus do not take up space.
You can put a comment in the middle of a command.
copy %SRC ^get files from \somedir ^ %DST ^ and put into \anotherdir ^
If you need a ^ as part of the text then preceed it with a %.
Leading spaces are eliminated while loading a shell file so please
use leading spaces freely to make shell files more readable and
maintaineable.
Included are a few sample shell files. Please take a look at them
to get a better idea of sh1 shell programming.
Shells may be debugged by entering the following command before
executing the shells:
debug +
Once the shell is invoked, each line of shell will be displayed and
a debug prompt "dbg> " will appear. Pressing return will cause
execution of that line. Please note that grav enclosed commands will
be executed before line is displayed.
A few one-letter debug commands are available at the debug prompt:
1. O or o display (O)riginal line ( before translation ).
2. E or e (E)dit translated line before it is executed.
3. I or i (I)nsert and execute a line before current line.
4. S or s (S)how status. Execute the SHOWSTAT command.
5. X or x e(X)amine an environment variable and change if desired.
6. B or b Insert a (B)reakpoint in current shell.
Sh1 will display a question mark and the first line
of the shell. Pressing the space bar will show the next
lines of the shell. Once you reach the desired line,
press return to indicate your choice. You may quit by
pressing the escape key.
8. L or l Insert breakpoint at this line and (L)oop around to it.
This command is useful for looping around any loop
construct and stopping at the same spot.
9. D or d Open a window to DOS. If the command is followed by a
string, that string will be executed and then wait for
a key to be pressed before returning to the debugger.
If the D alone is entered, a new copy of sh1 will be
loaded and allow you to execute any commands you may
desire. To return to debugger, enter EXITSH1 <return>.
10. C or c (C)ontinue execution of the shell without stopping.
The C command will cause the debugger to be disabled.
To debug again, enter the DEBUG command after the shell
finishes execution.
11. H or h The (H)elp will attempt to execute the command
LIST SH1.DOC
under a new copy of Sh1. If you don't have a listing utility
by the name of LIST you can create a shell called LIST.SH
which will invoke the listing utility you DO have.
Once you exit the listing utility, any key pressed will cause
the system to restore the debug screen.
12. Q or q (Q)uit shell execution.
13. P or p Break on (P)rocedure name. Sh1 will execute at full speed
until it encounters a call to the given procedure. This
breakpoint will remain active until an empty p command is
entered. The procedure name should follow the P with no
separating spaces. If the debug mode is off but the breakpoint
is active, the debug mode will be automatically enabled upon
reaching a procedure defined by P.
14. R or r Break on (R)eturn from procedure. The R command takes no
parameters. It will cause a breakpoint on the first return
from any procedure. It will cause Sh1 to run at full
speed until after a return is executed.
15. V or v (V)iew full output screen. The V command will cause the debug
lines to dissappear so you can see the full output screen.
To return to debug, press any key.
The X command should be followed with a variable name:
xSH1PROMPT
Once debug is finished, enter the following command to disable the
debug feature:
debug -
NOTES:
1. After sh1 is loaded it checks for the presence of a shell file
named "sh1init.sh". If present, this shell file is executed
automatically the same way AUTOEXEC.BAT is executed by command.com.
Sh1 does not look for sh1init.sh if it is invoked with command line
parameters.
2. The total active shell runtime space is limited to 64K bytes.
If you need HUGE shells, break them down to a main shell that
will invoke sub-shells. You will discover that most shells take up
very little room anyway. To see actual size of loaded shell, insert
in that shell a SHOWSTAT command or execute the shell after turning
the debug mode on and then enter the "s" debug command.
The "shell size" indicates how many bytes of shell are currently loaded.
Section 10. Compiling shell files.
Sh1 recognizes a type shell files with a suffix of .SHC which stands
for compiled shell. Once you have a working shell, you may use the
SHC.EXE to tokenize the shell and and save it under the same name but
with the new suffix .SHC. Most of the keywords are translated to a one
byte code and all leading spaces are deleted.
The advantages of compiling (or tokenizing) the shell file are:
- Tokenized files are smaller, thus are loaded faster and cause fewer
shell page swaps (transparent to the user but takes time).
- Execution time improves by up to 70% depending on what the shell does.
SHC.EXE outputs to standard output device so to save the output you have
to use the ">" redirection operator:
SHC eds.sh > eds.shc
NOTE:
Sh1 allows normal debugging of compiled shells by expanding the tokenized
lines while in debug mode.
Section 11. Defining the prompt and sh1 temporary file directory.
11.1 SH1PROMPT
The default sh1 prompt is "sh1>". Not very informative, hah?
Well... sh1 has the same mechanism as command.com for defining
a prompt string. The environment variable SH1PROMPT is used to contain
that definition. Special escape sequences in the prompt are entered as
a Dollar sign followed by a single character.
Notice that the variable name has changed from PROMPT to SH1PROMPT to
avoid conflict with command.com.
The following list shows all the escape sequences currently implemented
in sh1:
$$ Output the Dollar sign
$d Output the current disk drive name
$p Output the current directory path
$g Output >
$l Output <
$b Output |
$c Clear screen
$n Output <cr><lf>
$r Output <cr>
$t Output a tab
Examples:
SH1PROMPT=$d$p$g
SH1PROMPT=$c$n$n$nNext?
You can initialize the prompt in the sh1init.sh mentioned above.
11.2 SH1FILES
The sh1 system uses some temporary data files. If you have a
Ram-disk and you would like sh1 to put these files there,
add a line to your sh1init.sh:
SH1FILES=<subdir>
If you do not specify SH1FILES, the default is the root directory
of the currently selected disk drive.
Section 12. Bugs and other funny phenomena.
For some weird reason, the JET utility of Tall Tree Systems will
not work properly if the JET command line is not terminated with
I/O redirection.
To use JET enter:
JET src dst params> con:
ANSI.SYS, if loaded, causes the grav mechanism to always return an
empty string.
----------------------------------------------------------------------------
Appendix A - History of changes up to V1.08A inclusive.
2.0 Only commands of more than 3 characters get logged in history queue.
2.1 Ver 1.01 sh1 allowed alphabetic variable names ONLY.
Ver 1.02 is fixed to allow digits in names.
2.2 If and While statements with long strings caused system to hang. Fixed.
2.3 Commands with I/O redirection or piping got logged twice into the
history file. Fixed.
2.4 Multiple-line echo statements can now be written or appended to a file
by putting > or >> respectively after closing exclamation point.
2.5 The variable %0 returns all parameters passed to a shell chained
together.
2.6 Showstat command can be made to display sh1 version by adding a "v"
switch. Ex. showstat v <cr>
2.7 History manipulation:
Pressing Down arrow enters history mode without displaying the
recorded command lines.
2.8 The HELP command has been removed to conserve space.
2.9 The shx -d option has been expanded to allow finer control of output.
See shx description below.
2.10 Starting with V1.04, and ELSE statement can be followed with an IF
for forming the construct IF ... ELSE IF ... ELSE IF ... ELSE ... ENDIF
2.11 V1.04 - "shx -sr" added for removing a substring from a string.
This can be convenient if you know that a string contains a certain
substring which you want to remove. If substring is not found then
the whole string is returned.
2.12 V1.05 modifications:
2.12.1 History mechanism completely changed. Now, when you press up-arrow
the system lists up to 24 of the latest commands to enter the queue.
It then positions the cursor on the last command. Use the up and
down arrows and Home and End to point to desired command.
Once the cursor points to the desired command, you may enter E to
edit it, D to delete it or <enter> to execute it as is.
You may also delete a few commands by repeatedly positioning the
cursor and hitting D. If the command being deleted is longer than
one line, the History mode will be exited. That is done due to the
fact that deleted lines' length cannot be determined for cursor
movement.
To clear the whole buffer, press C.
The down arrow entry into History has been disabled.
I took out the load/save features to minimize sh1 size. If many
people will be angry, I will put it back in.
2.12.2 A few special variables were added. See the section on variables.
2.12.3 Regular command.com batch files are now recognized and executed
in addition to the shell files. If you have an extensive collection
of batch files, you don't have to modify them to shells.
2.12.4 Fixed compute command to handle signed long integers.
2.12.5 Changed the line editing to jump to words delimited by non-
Alphanumeric characters instead of only space.
2.13 V1.06
Oops, v1.05 had a little cosmetic bug in the history mechanism.
The first time the history was invoked after entering a new command,
an extra blank line appeared on line 24. V1.06 fixes this one tiny
problem.
2.14 V1.07
Fixed another tiny bug in the CALL command.
EXIT command now has an optional return value.
Shx has new file listing options (b,p).
Sh1 can now be called with command line parameters for single
shell execution (e.g. sh1 <shell-name> <parameters>...).
Exitsh1 can be executed from within a shell and may specify
ERRORLEVEL code.
Shx -c option (count lines/words/chars) can now also operate
as a filter.
Sh1 did not execute pipes within gravs correctly. Fixed.
2.15 V1.08
A one-line echo following a multi-line echo would crash sh1. Fixed.
Condition statements can contain multiple tests now.
Arithmetic/logic Expressions are fully algebraic including
parentheses.
A new shell debug facility has been added (See section 9).
Maximum shell size has been increased to 64K bytes.
Case statements may now have multiple cases per block.
The ACCEPT statement has an optional -e switch for editing the
contents of a variable instead of just filling it with a new string.
A new special variable %! returns a single character from keyboard.
The ECHO statement will omit the newline character if last character
is an underline ( cursor will stay to right of string ).
NEW commands:
REPEAT ... UNTIL <expr>
FOR <var> IN <list> ... ENDFOR
FOR <var> INFILE <textfile> ... ENDFOR
The READ command has been enhanced to be able to get the next word
from the FOR list (READ f <destvar>).
Shx -zb option added for creating empty files.
Shx has two new file listing options (t,m) for displaying file
modification date.
Shx has two new options for saving the screen to a file and painting
the screen from a file ( -scrs and -scrl respectively ).
2.16 V1.08A
Fixed a bug found in V1.08 which caused sh1 to get confused if it
saw a " in the parameter list of a shell.
A new command has been added to allow local variables in shells
(see LOCAL command).
----------------------------------------------------------------------------
Appendix B - Shx usage examples.
The enclosed shell files contain many examples of shx usage. Please take
a look at them. The Shx is mainly used in conjunction with the grav
mechanism of Sh1. Most of its options cause shx to output a single line
to standard output (the exceptions are the -wd, -d, -ms, -scrl, -scrs,
-scrt and -zb options which do not send anything to standard output).
Example 1 - Get total size of all files in this directory with a prefix of
.COM and subtract it from total size of files ending with .EXE.
Echo the difference.
compute DIFF=`shx -dz *.exe` - `shx -dz *.com`
echo %DIFF
Example 2 - Compile a "C" program only if source is more recent than its
object file. The -mc option returns the number of seconds
of difference between the modification date/time of the two
files.
if `shx -mc program.c program.obj` >= 0
msc program;
endif
Example 3 - Extract the third word of the fifth line of a text file.
LINE=`shx -xt file 5`
WORD=`shx -sw %"%LINE%" 3`
echo '%WORD' is the 3rd word in '%LINE'
Example 4 - Add the numeric values of two variables and get sum in
hexadecimal format with leading 0 and trailing H.
SUM=`shx -aX %"%VAR1 + %VAR2%"`
echo %VAR1 + %VAR2 = 0%{SUM}H
The same result canbe obtained from a single more complicated line:
echo %VAR1 + %VAR2 = 0`shx -aX %"%VAR1 + %VAR2%"`H