mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-22 00:32:44 +00:00
A log of updated docs. Partial scripts being developed.
This commit is contained in:
parent
cf54cc26b4
commit
e1cdb6f089
@ -1,7 +1,7 @@
|
||||
|
||||
# A2osX Shell Developers Guide
|
||||
|
||||
### Updated November 19, 2019
|
||||
### Updated November 20, 2019
|
||||
|
||||
One of the most significant parts of A2osX is its shell which can perform both interactive and scripted tasks. With the interactive part of the shell you can perform many common and complex tasks using both built-in (native or internal to shell) and external (BIN or executable) commands. Internal commands include CD (change directory), MD (make directory), PWD, DATE, etc. External commands include CP (copy), RM (remove), CAT (display file contents), TELNET, etc.
|
||||
|
||||
@ -15,17 +15,17 @@ In this example, the system will generate a list of files found in the current d
|
||||
|
||||
This Developers Guide will cover the basic operation of the interactive shell, the internal shell commands and creating complex scripts that can be run by the shell. For information on external commands consult the **[A2osX Command Guide](Command%20Guide.md)**.
|
||||
|
||||
## The A2osX Shell (SH)
|
||||
## About the A2osX Shell (SH)
|
||||
|
||||
The default A2osX Shell **./BIN/SH** is an external command program like many others included with A2osX. It is probably the most complex and capable, as suggested by its size compared to other commands (7K vs 1K for TELNET). It is the primary tool for interacting with the A2osX system. The SH shell is based loosely on the Linux BASH shell, to the extent possible on an 8-bit machine. Alternative shells are planned for the future and will be announced as they become available.
|
||||
|
||||
As the primary mechanism for working with A2osX, the SH shell is launched automatically when you log into A2osX. In the case where no ./ETC/PASSWD file is present, A2osX automatically logs you in as the ROOT user. When a user login occurs and SH is launched, it looks for a file called PROFILE in the users HOME directory and if found executes that script, so the information below on writing scripts applies to PROFILE script files.
|
||||
|
||||
### Interacting with the Shell
|
||||
## Interacting with the Shell
|
||||
|
||||
To interact with the A2osX shell, you type commands at the prompt, which ends with a **$** character. The prompt usually includes your current working directory such as **/FULLBOOT/ROOT/$**. You can change the prompt by changing the **$PS1** variable (see below). At the **$** you can enter any of the valid internal shell commands, an external program file name or a script file name. For external programs and scripts, A2osX will search in the current directory and then in the directories specified in the **$PATH** variable.
|
||||
|
||||
#### Special Keys
|
||||
### Special Keys
|
||||
|
||||
While entering commands at the A2osX shell prompt, you can use the following special keys to edit the command line:
|
||||
|
||||
@ -48,7 +48,7 @@ In addition to the editing keys above, you can use the following special keys wh
|
||||
| Open Apple-0 | Switches you to the console display |
|
||||
| Open Apple-1 to 4 | Switches you to Virtual Terminals 1 through 4 if so configured |
|
||||
|
||||
### Internal Commands
|
||||
## Internal Commands
|
||||
|
||||
The A2osX Shell contains an advanced set of internal commands. Several of these commands are typically used interactively (at the $ prompt) while others are typically used in scripts. Technically all of these commands can be used both interactively or in scripts, though many really only show their power in scripts you develop or run.
|
||||
|
||||
@ -61,13 +61,13 @@ where in the first nomenclature a **command** performs an action with or on the
|
||||
|
||||
> A note on command line structure for internal and external commands: When passing a command a series of arguments, you must include a space between each argument. In addition, if a command has an option that requires an argument, there must also be a space between the option and its argument. For example, when using the READ command which has the -S -P and -N options, the -P and -N options both require an argument so the full use of the command would be **READ -S -N 3 -P "My Prompt" AVAR**. Do not use -N3 as you might in Linux or DOS as you will generate a Syntax Error and the command will fail to execute. Also note, for many commands the order of the arguments is important (i.e. CP sourcefile destfile, order critical), however the order of Options is not. **READ -S -N 3 -P "MyPrompt" AVAR** is the same as **READ -P "MyPrompt" AVAR -S -N 3 ** as well as **READ -S AVAR -N 3 -P "MyPrompt"**. What is critical here is that you **must** have a number immediately after -N and a string after -P which will be the prompt.
|
||||
|
||||
#### Arguments
|
||||
### Arguments
|
||||
|
||||
As briefly discussed above, almost all commands take and most even require an argument which affects the command's behavior. For example the **SLEEP** command requires that you pass it an argument that indicates the amount of time to SLEEP. Arguments come in many forms; each of these is discussed here.
|
||||
|
||||
##### \<conditions\>
|
||||
#### \<conditions\>
|
||||
|
||||
The shell features a lot of built-in checks and comparisons called \<conditions\> throughout this guide. This particular form of an argument is used exclusively by the **IF** and **WHILE** commands where the \<condition\> is evaluated and result is used to control program flow with in the defined **IF-ELSE-FI** or **WHILE-LOOP** block. In addition to the capabilities found in the extensive list of checks and comparisons listed below, conditional execution can be enhanced by negating with an ! in front of a condition and/or compounding with AND and OR between two or more conditions. The following scripts show examples of the possible conditions you can use while writing your own scripts.
|
||||
The shell features a lot of built-in checks and comparisons called \<conditions\> throughout this guide. This particular form of an argument is used exclusively by the **IF** and **WHILE** commands where the \<condition\> is evaluated and result is used to control program flow with in the defined **IF-ELSE-FI** or **WHILE-LOOP** block. All conditions must be encloded with in brackets **[]**. In addition to the capabilities found in the extensive list of checks and comparisons listed below, conditional execution can be enhanced by negating with an ! in front of a condition and/or compounding with AND and OR between two or more conditions. The following scripts show examples of the possible conditions you can use while writing your own scripts.
|
||||
|
||||
> Note: The examples below make use of the **;** directive which allows you to put multiple statements on one line. So for example
|
||||
|
||||
@ -83,24 +83,26 @@ The shell features a lot of built-in checks and comparisons called \<conditions\
|
||||
|
||||
> The single line notation allows these sample scripts to be significantly shorter; their operation is not affected. Also note, you are not limited to a single command line between the IF/ELSE/FI statements. See the documentation of the IF command for more information.
|
||||
|
||||
This script demonstrates the usage of the various "Check" Conditions.
|
||||
The shell includes several "checks" that can be used to easily determine if certain \<conditions> are true or false. The format of a check is **[ -CHECK \<value> ]** where -CHECK is one **-D** (is a directory), **-E** (is a directory or a file), **-F** (is a file), **-I** (is an integer), **-N** (is a null) or **-Z** (is not null) and where \<value> is a variable or literal on which to perform the check. This script demonstrates the usage of these "Check" Conditions.
|
||||
|
||||
#!/BIN/SH
|
||||
#
|
||||
# IF [ -CHECK arg ] Examples
|
||||
# IF [ -CHECK <value> ] Examples
|
||||
#
|
||||
# Echo "Found" if their is a subdirectory TEST is in the current directory
|
||||
# If TEST is not present, or is present but a file, this Check would fail
|
||||
IF [ -D TEST ] ; ECHO "Found" ; FI
|
||||
# If -D using a variable
|
||||
SET FNAME = "TEST" ; IF [ -D $FNAME ] ; ECHO "Found" ; FI
|
||||
# Echo "Found" if a file or a subdirectory named TEST is in the current directory
|
||||
IF [ -E TEST ] ; ECHO "Found" ; FI
|
||||
# Echo "Found" if the file PROFILE is in the top most directory of the volume MYVOL
|
||||
# IF PROFILE were a directory name and not a file, this Check would fail
|
||||
IF [ -F /MYVOL/PROFILE ] ; ECHO "Found" ; FI
|
||||
# Echo "True" if the variable ABC contains an Integer
|
||||
# Echo "True" if the <value> is an Integer
|
||||
SET ABC = 123 ; IF [ -I $ABC ] ; ECHO "True" ; FI # Would Echo True
|
||||
SET ABC = "Hello" ; IF [ -I $ABC ] ; ECHO "True" ; FI # False no Echo
|
||||
SET ABC = 123.456 ; IF [ -I $ABC ] ; ECHO "True" ; ELSE ; ECHO "False" ; FI # Echo False
|
||||
IF [ -I 123.456 ] ; ECHO "True" ; ELSE ; ECHO "False" ; FI # Echo False
|
||||
# Note the next two -N and -Z are in affect opposites of each other ![ -N ] = [ -Z ]
|
||||
# Echo "True" if the variable is not empty (non-null)
|
||||
SET ABC = "Hello" ; IF [ -N $ABC ] ; ECHO "True" ; FI # True
|
||||
@ -197,7 +199,7 @@ You can further extend \<conditions\> by building complex evaluations that consi
|
||||
|
||||
When using multiple of these joiners with a single command such as **IF**, care should be made in the structuring of your \<condition\> statements. The shell processes command lines linearly from left to right and is very binary in nature. Consider first a math example of **SET A = 1 + 2 * 3 - 4 * 8 + 2 / 2**, the result placed into **A** is 42 (process the calculations like a calculator would, one at a time, there is no precedence). When evaluating a set of \<conditions\>, the shell processes them one at a time the same way and when it encounters an AND or an OR it evaluates the current "state" to determine if it should return a result or continue to evaluate the conditions ont he line. Let us say you have 4 conditions, A, B, C and D (each one represents something like [ -d adir ]), and you are doing something like IF A AND B OR C AND D. The Shell will determine a result for A (for example that [ -d adir]) and then it sees "AND", at that moment if A is false all processing ends there because it does not matter what else is on the command line (The IF fails). Now assume A and B are both true and it gets to that OR, again processing stops be cause there is already a true case on one side of the OR (The IF succeeds). As you can see, its easy to predict the behavior of constructs like IF A and B and C and D (all must be true) as well as IF A or B or C (any one need be true), but complex IF A or B and C or D and E need to be tested that they perform as you imagined. Once mastered though, you will see that when structured correctly you can perform very complex \<condition\> sets. Say you wanted to do IF ( A and B ) or C, realizing there is no actual groupings (parens) in conditions, if you simply structure your if as IF C OR A AND B, it will have the effect you wanted. There is an example of complex compound conditions that you can run and even modify to test different patterns/structures of complex conditions. It can be found at **[ANDORTESTS](../EXAMPLES/ANDORTESTS.txt)**.
|
||||
|
||||
##### \<expression\>
|
||||
#### \<expression\>
|
||||
|
||||
The A2osX shell contains a expression evaluator that can perform simple integer math operations using the \+ \- \* \/ and MOD operators. Expressions are a form of an argument used by only a handful of commands, most notably SET (to store the result of the expression into a variable) and CASE/SWITCH.
|
||||
|
||||
@ -213,80 +215,158 @@ The A2osX shell contains a expression evaluator that can perform simple integer
|
||||
SET C = A / B # 12
|
||||
SET C = A MOD B # 3
|
||||
|
||||
##### \<op\>
|
||||
#### \<op\>
|
||||
|
||||
\<Op\> are operators, the simple integer math functions that can be performed in the shell. They are a special kind of argument used only in \<Expressions\>, see above. The valid \<Ops\> are \+ \- \* \/ and MOD.
|
||||
\<Op\> are operators, the simple integer math functions that can be performed in the shell. They are a special kind of argument used only in \<Expressions\>, see above. The valid \<Ops\> are \+ (addition) \- (subtraction) \* (multiplication) \/ (division) and MOD. See the script above in the \<expression> section for examples of \<ops>.
|
||||
|
||||
##### \<switch\>
|
||||
#### \<switch\>
|
||||
|
||||
A switch is a special type of argument to internal and external commands that changes the behavior of that command. For instance, the standard ECHO command ends its output with a carriage return (ASCII 13), adding the -N switch to ECHO (i.e. ECHO -N "Hello") will cause ECHO to omit the CR. All switches begin with hyphen (-) and are immediately followed by a valid single character (in the case of ECHO -N is the only valid switch) and then a space (or carriage return if the end of the line). There should be no space between the hyphen (-) and the switch character, and if the switch itself requires an argument, then switch must be followed by a space and then the argument for that switch (see the READ command for an example). Please make sure you read the note at the start of this section regarding command line structure and the ordering of arguments, in particular with switches that themselves require arguments.
|
||||
|
||||
##### \<value\>
|
||||
#### \<value\>
|
||||
|
||||
Values are the simplest of arguments, usually a string or an integer, which may be presented in the form of a variable. Technically the format of the ECHO command is **ECHO [-N] [\<value\> ...]**. This means that the ECHO command can be followed by the optional switch -N and one or more optional \<values\>. In the case of ECHO, it is these \<values\> that are output by the command. In this case, values are separated by spaces, so you can do ECHO $A HELLO $B and echo will output the value stored in the variable A and then the world HELLO and then the value stored in B. A word about values, command lines and spaces: **ECHO Hello World** is not the same as **ECHO "Hello World"**. In the first case you ECHO treats Hello and World as separate values and in the second, "Hello World" as one value. Since ECHO takes multiple values, you might not notice the difference, but in the case of **IF [ $A = "Hello World" ]** if you omitted the quotes you would get a syntax error because the = operator only accepts one value on each side. In addition, when not enclosed in quotes, extra spaces are removed so **ECHO Hello World"** would be output as **Hello World** as ECHO would treat each Hello and World as values and output value space value.
|
||||
Values are the simplest of arguments, usually a string or an integer, which may be presented literally or in the form of a variable.
|
||||
|
||||
#### AND
|
||||
Please note, that the shell does string substitution when processing \<values>. This is done when the shell finds a variable within the string (a set of characters that begin with a $). For example if you had a variable called $BOOTVOL that is set to "/MYVOL/" and you passed a command the \<value> "${BOOTVOL}AFILE" would get expanded to "/MYVOL/AFILE". Notice the use of braces **{}** surrounding the variable name, they are needed here otherwise the SHELL would look for the variable $BOOTVOLAFILE. See the script below for the **ECHO** command for more examples of values that contain variables.
|
||||
|
||||
### AND
|
||||
|
||||
IF|WHILE [ <\expression\> ] AND [ <\expression\> ]...
|
||||
|
||||
The **AND** reserved word is used to join 2 or more conditions together to create complex logic statements. See \<condition\> section above for more information on **AND** and examples of its usage. In addition, look at **[ANDORTESTS](EXAMPLES/ANDORTESTS.txt)**, a complete script using **AND**.
|
||||
|
||||
#### BREAK
|
||||
### BREAK
|
||||
|
||||
BREAK
|
||||
|
||||
The **BREAK** command is used to exit a particular **CASE** that is part of a **SWITCH** script block. See the **CASE** command below for more information and example of using **BREAK**.
|
||||
The **BREAK** command is used to exit or end a block of statements that were optionally executed for a particular **CASE** as part of a **SWITCH** script block. See the **CASE** command below for more information and example of using **BREAK**.
|
||||
|
||||
#### CALL
|
||||
### CALL
|
||||
|
||||
CALL function [\<argument\>]...
|
||||
|
||||
The **CALL** command is used to execute and previously defined and loaded function. When calling a function with the **CALL** command, you may pass one or more arguments which the function can use as part of its execution. See the **FUNCTION** command below for more information on creating and calling functions including examples.
|
||||
| CALL | Working | CALL function \<arg\> ... |
|
||||
|
||||
#### CASE
|
||||
### CASE
|
||||
|
||||
CASE <expression>
|
||||
|
||||
#### CD
|
||||
The **CASE** command is used at the start of a block of statements to be optionally executed based on the evaluation of \<expression\> as part of a **SWITCH** script block. See the **CASE** command below for more information and example of using **BREAK**.
|
||||
|
||||
CD path
|
||||
### CD
|
||||
|
||||
CD <value>
|
||||
|
||||
The **CD** command is used to change the current working directory. You must supply the **CD** command a valid relative or absolute path. Examples of relative paths include SUBDIR1 (a sub-directory in the current directory), ../SUBDIR2 (a sub-directory in the parent of the current directory), and SUBDIR1/SUBDIR3 ( a subdirectory in the subdirectory SUBDIR1 of the current directory). An absolute path always begins with a / and includes the volume name of the disk drive to which change the current working directory such as /MYVOL1/VAR/LOGS (the subdirectory LOGS in the directory VAR on the disk with a volume label of MYVOL1).
|
||||
|
||||
#### DATE
|
||||
### DATE
|
||||
|
||||
| DATE | Working | %a : Abbreviated weekday name : Thu <br> %A : Full weekday name : Thursday <br> %b : Abbreviated month name : Aug <br> %B : Full month name : August <br> %d : Day of the month, zero-padded (01-31) <br> %H : Hour in 24h format (00-23) 14 <br> %I : Hour in 12h format (01-12) 02 <br> %m : Month as a decimal number (01-12) 08 <br> %M : Minute (00-59) 55 <br> %p : AM or PM designation PM <br> %S : Second (00-61) 02 <br> %w : Weekday as a decimal number with Sunday as 0 (0-6) <br> %y : Year, last two digits (00-99) <br> %Y : Year four digits 2001 |
|
||||
DATE [<expression>]
|
||||
|
||||
#### DEFAULT
|
||||
The **DATE** command outputs the current date and time. A supported clock card is needed to return accurate DATE and TIME values. **DATE** accepts an optional \<expression> that should be a string that can contain any text as well as the following format options:
|
||||
- %a : Abbreviated weekday name : Thu
|
||||
- %A : Full weekday name : Thursday
|
||||
- %b : Abbreviated month name : Aug
|
||||
- %B : Full month name : August
|
||||
- %d : Day of the month, zero-padded (01-31)
|
||||
- %H : Hour in 24h format (00-23) 14
|
||||
- %I : Hour in 12h format (01-12) 02
|
||||
- %m : Month as a decimal number (01-12) 08
|
||||
- %M : Minute (00-59) 55
|
||||
- %p : AM or PM designation PM
|
||||
- %S : Second (00-61) 02
|
||||
- %w : Weekday as a decimal number with Sunday as 0 (0-6)
|
||||
- %y : Year, last two digits (00-99)
|
||||
- %Y : Year four digits 2001
|
||||
|
||||
The following script highlights sample \<expressions> you can pass the **DATE** command.
|
||||
|
||||
#!/BIN/SH
|
||||
#
|
||||
# DATE Command Examples
|
||||
#
|
||||
DATE ' Wednesday, November 20 2019 22:53:00
|
||||
DATE "Time: %I:%M %p" ' Time: 10:53 PM
|
||||
DATE "Today is %A %B %d %Y" ' Today is Wednesday November 20 2019
|
||||
DATE "%b-%d-%y" ' Nov-20-19
|
||||
|
||||
### DEFAULT
|
||||
|
||||
DEFAULT
|
||||
|
||||
The **DEFAULT** commands is used to select the block of commands to execute for the Default Case for the **SWITCH** command. Structured appropriately, the commands after the **DEFAULT** keyword are executed when no other **CASE** was valid. See the section on **CASE** and **SWITCH** for more information and complete examples for creating your own **SWITCH** login/execution blocks.
|
||||
|
||||
#### ECHO
|
||||
### ECHO
|
||||
|
||||
| ECHO | Working | \b,\e,\f,\n,\\\ and \\% supported <br> -N : Suppress \r\n |
|
||||
ECHO [-N] <value>...
|
||||
|
||||
#### ELSE
|
||||
The **ECHO** command is used to print <values> to an output device, by default the screen. The **ECHO** command optional switch **-N** causes **ECHO** to suppress output of the carriage return that normally occurs. Technically the format of the ECHO command is **ECHO [-N] [\<value\> ...]**. This means that the ECHO command can be followed by the optional switch -N and one or more optional \<values\>. In the case of ECHO, it is these \<values\> that are output by the command. Here, values are separated by spaces, so you can do ECHO $A HELLO $B and echo will output the value stored in the variable A and then the world HELLO and then the value stored in B. Please see \<values> for more information on how values are processed, especially in the handling of variables ($VAR) contained in a \<value>.
|
||||
|
||||
| ELSE | Working | Optional branch for IF block |
|
||||
A word about values, command lines and spaces: **ECHO Hello World** is not the same as **ECHO "Hello World"**. In the first case you ECHO treats Hello and World as separate values and in the second, "Hello World" as one value. Since ECHO takes multiple values, you might not notice the difference, but in the case of **IF [ $A = "Hello World" ]** if you omitted the quotes you would get a syntax error because the = operator only accepts one value on each side. In addition, when not enclosed in quotes, extra spaces are removed so **ECHO Hello World** would be output as **Hello World** as ECHO would treat Hello and World as values and output value space value.
|
||||
|
||||
#### END
|
||||
\b,\e,\f,\n,\\\ and \\% supported <br> -N : Suppress \r\n |
|
||||
|
||||
| END | Working | End of SWITCH Statement |
|
||||
#!/BIN/SH
|
||||
#
|
||||
# ECHO Command Examples
|
||||
#
|
||||
ECHO Hello World 'Hello World #Note SH treats as 2 <values>
|
||||
ECHO "Hello World" 'Hello World
|
||||
ECHO \f 'Clears Screen
|
||||
ECHO "\fHello" 'Clears Screen puts Hello on first line
|
||||
ECHO "\n\nHello' 'Sends to Carraige Returns then Hello to output
|
||||
SET A$ = HELLO
|
||||
ECHO A$ 'HELLO
|
||||
ECHO "$A, How are you?" 'HELLO, How are you?
|
||||
ECHO "$AB, fine!" ', fine! #Note AB is not defined
|
||||
ECHO "${A}B, fine!" 'HELLOB, fine! #Brackets ensure A substitution
|
||||
ECHO "123\b\b456" '1456 #two backspaces (\b) over the 23
|
||||
|
||||
#### EXIT
|
||||
### ELSE
|
||||
|
||||
| EXIT | Working | exit function, script or shell |
|
||||
ELSE
|
||||
|
||||
#### FI
|
||||
The **ELSE** command is used to add an optional branch to an **IF** block. See the **IF** command below for more information and examples of using **ELSE** as part of **IF** program blocks.
|
||||
|
||||
| FI | Working | Terminator for IF block |
|
||||
### END
|
||||
|
||||
#### FUNCTION
|
||||
END
|
||||
|
||||
| FUNCTION | Working | FUNCTION function_name { <br> \<body\> <br> } |
|
||||
The **END** command is used at the end of a **SWITCH** script block. See the **SWITCH** command below for more information and example of using **END** as part of **SWITCH**.
|
||||
|
||||
### EXIT
|
||||
|
||||
EXIT [int32]
|
||||
|
||||
The **EXIT** command is used to immediately end the processing of a script or function. **EXIT** accepts an optional argument that sets the return code (**$?**) which may be checked by a calling script. If no argument is provided the return code is set to 0 (No Error).
|
||||
|
||||
#!/BIN/SH
|
||||
#
|
||||
# EXIT Command Examples
|
||||
#
|
||||
# THis example shows the use of EXIT from a function with a return code
|
||||
#
|
||||
FUNCTION DIVIDE
|
||||
{
|
||||
SET $3
|
||||
}
|
||||
READ -P "Enter a number: " $A
|
||||
READ -P "Another number: " $B
|
||||
CALL DIVIDE $A $B C
|
||||
|
||||
|
||||
### FI
|
||||
|
||||
FI
|
||||
|
||||
Terminator for IF block
|
||||
|
||||
### FUNCTION
|
||||
|
||||
FUNCTION function_name
|
||||
{
|
||||
\<body\>
|
||||
}
|
||||
|
||||
if you SET -F, it will discard ALL previously learnt FUNC in the current SH context
|
||||
if . FUNCS1 file add 3
|
||||
@ -302,52 +382,52 @@ FUNCs recursion is allowed (until you explode the stack!)
|
||||
CORE.STACK.MAX = 128....so each CALL consumes about 7 bytes of stack (return Ctx/Ptr, ArgVC,hArgV and CALL keywordID)
|
||||
|
||||
|
||||
#### IF
|
||||
### IF
|
||||
|
||||
IF [ <\expression\> ]...
|
||||
|
||||
|
||||
#### LOOP
|
||||
### LOOP
|
||||
|
||||
LOOP
|
||||
|
||||
The **LOOP** command...
|
||||
|
||||
#### MD
|
||||
### MD
|
||||
|
||||
| MD | Working | MD path or relative path <br> Create a directory |
|
||||
|
||||
#### NOHUP
|
||||
### NOHUP
|
||||
|
||||
| NOHUP | Working | Start a process with PPID=PS0 (Daemon) |
|
||||
|
||||
#### OR
|
||||
### OR
|
||||
|
||||
IF|WHILE [ <\expression\> ] OR [ <\expression\> ]...
|
||||
|
||||
The **OR** reserved word is used to join 2 or more conditions together to create complex logic statements. See \<condition\> section above for more information on **OR** and examples of its usage. In addition, look at **[ANDORTESTS](EXAMPLES/ANDORTESTS.txt)**, a complete script using **OR**.
|
||||
|
||||
#### PAUSE
|
||||
### PAUSE
|
||||
|
||||
| PAUSE | Working | Wait until CR |
|
||||
|
||||
#### POPD
|
||||
### POPD
|
||||
|
||||
| POPD | Working | Restore previously saved working directory |
|
||||
|
||||
#### PUSHD
|
||||
### PUSHD
|
||||
|
||||
| PUSHD | Working | Save actual working directory <br> PUSHD \<dir\> do also a CD to \<dir\> |
|
||||
|
||||
#### PWD
|
||||
### PWD
|
||||
|
||||
| PWD | Working | Print Working Directory |
|
||||
|
||||
#### RD
|
||||
### RD
|
||||
|
||||
| RD | Working | Delete an empty directory |
|
||||
|
||||
#### READ
|
||||
### READ
|
||||
|
||||
| READ | Working | -S : no echo (password) <br> -P : "prompt message" <br> -N maxchar |
|
||||
|
||||
@ -376,7 +456,7 @@ The READ command allows you to accept input from the user which can be used or e
|
||||
# This can be used to capture/process special keys like TAB, Arrows and DEL.
|
||||
READ -N 0 A
|
||||
|
||||
#### REN
|
||||
### REN
|
||||
|
||||
| REN | Working | Rename a file, directory or volume |
|
||||
|
||||
@ -406,27 +486,37 @@ The REN command allows you to Rename a single file, directory or Volume. It doe
|
||||
# REName a file using a full path
|
||||
REN /FULLBOOT/TMP/MYFILE NEWFILENAME
|
||||
|
||||
#### SET
|
||||
### SET
|
||||
|
||||
| SET | Working | -X : toggle debug mode <br> -C : toggle Control-C break mode <br> -E : toggle error printing mode <br> -F : delete all declared functions |
|
||||
|
||||
#### SHIFT
|
||||
### SHIFT
|
||||
|
||||
| SHIFT | Working | Remove $1 from cmd line |
|
||||
SHIFT
|
||||
|
||||
#### SLEEP
|
||||
Remove $1 from cmd line
|
||||
|
||||
| SLEEP | Working | Wait \<count\> 10th sec |
|
||||
### SLEEP
|
||||
|
||||
#### SWITCH
|
||||
SLEEP int32
|
||||
|
||||
| SWITCH | Working | SWITCH <expression> |
|
||||
Wait 1/10 sec
|
||||
|
||||
#### WHILE
|
||||
### SWITCH
|
||||
|
||||
| WHILE | Working | [ \<condition\> ] |
|
||||
SWITCH <expression>
|
||||
|
||||
### Redirection
|
||||
The **CASE** command is used at the start of a block of statements to be optionally executed based on the evaluation of \<expression\> as part of a **SWITCH** script block. See the **CASE** command below for more information and example of using **BREAK**.
|
||||
|
||||
|
||||
The **SWITCH** statement is used at the start of a multiway program flow control block statement. The **SWITCH** statement is really a different form of the **IF** statement that is a significant improvement over using **IF** with many nested **ELSE ; IF** blocks. **SWITCH** provides an easy way to dispatch execution to different parts of code based on the value of the expression. Switch is a control statement that allows a value to change control of execution.
|
||||
|
||||
|
||||
### WHILE
|
||||
|
||||
WHILE <condition>
|
||||
|
||||
## Redirection
|
||||
|
||||
| Token | Status | Comment |
|
||||
| ---- | ------ | ------- |
|
||||
@ -441,13 +531,13 @@ The REN command allows you to Rename a single file, directory or Volume. It doe
|
||||
| 2>> | Working | StdErr redirection |
|
||||
| 2> | Working | |
|
||||
|
||||
### Writing Scripts
|
||||
## Writing Scripts
|
||||
|
||||
Calling other scripts
|
||||
calling scripts with . (dot space) before script name from within a script
|
||||
loading functions this way
|
||||
|
||||
#### Variables
|
||||
### Variables
|
||||
|
||||
Variable overflow strings and ints
|
||||
Ints only no real num it just ignore
|
||||
@ -456,7 +546,7 @@ The 32-bit int data type can hold integer values in the range of −2,147,483,64
|
||||
|
||||
Strings can be up to 255 characters in length. Note, like INTs, if you try to store more then 255 chars in a string, you get the same wraparound affect where the first 255 chars are tossed out the string is set to the remaining chars, so if you concatenate 3 strings of 100 chars the resulting string will be the last 45 chars of the 3rd original string.
|
||||
|
||||
##### Special Variables
|
||||
#### Special Variables
|
||||
|
||||
$BOOT
|
||||
$DRV
|
||||
|
@ -18,8 +18,8 @@ This is the functional specification for A2osX and its system modules, internal
|
||||
| Name | Status | Comment | K.Ver |
|
||||
| ---- | ------ | ------- | ------|
|
||||
| GETTY | Working | -E : Exit on remote close | 0.93 |
|
||||
| HTTPD | Future | Web Page Server Daemon | |
|
||||
| INITD | In Progress | Run Level Manger | 0.93 |
|
||||
| HTTPD | In Progress | Web Page Server Daemon | 0.94 |
|
||||
| INITD | In Progress | Run Level Manger | 0.94 |
|
||||
| INSDRV | Working | Loads HW Drivers | 0.93 |
|
||||
| KCONFIG | Working | Kernel Configuration Utility | 0.93 |
|
||||
| LOGIN | Working | Authorization using /etc/passwd | 0.93 |
|
||||
@ -35,7 +35,7 @@ This is the functional specification for A2osX and its system modules, internal
|
||||
| Mouse.DRV | Future | Apple Mouse Card/Mouse Port | |
|
||||
| PIC.DRV | Future | Apple "Parallel Interface Card" Driver, renamed from PPIC.DRV | |
|
||||
| SSC.DRV | Working | Apple "Super Serial Card" Driver | 0.93 |
|
||||
| SSC.I.DRV | In Progress | Apple "Super Serial Card" Driver (IRQ enabled) | 0.93 |
|
||||
| SSC.I.DRV | Working | Apple "Super Serial Card" Driver (IRQ enabled) | 0.93 |
|
||||
| Uthernet.DRV | Working | Ethernet Network Interface | 0.93 |
|
||||
| Uthernet2.DRV | Working | Ethernet Network Interface | 0.93 |
|
||||
| Uther2.AI.DRV | In Progress | Network Interface With ARP/IP Offloading | 0.93 |
|
||||
@ -57,7 +57,7 @@ This is the functional specification for A2osX and its system modules, internal
|
||||
| EDIT | Working | still missing : find/replace | 0.93 |
|
||||
| FORMAT | In Progress | FORMAT \<BLOCKDEV\> [VOLUME.NAME] <br> -B Blocks : Force number of blocks to format <br> -L : Low-Level Format *not currently supported <br> -1..9 : Catalog Size (block count) | 0.93 |
|
||||
| GREP | Working | GREP \<opt\> PATTERN FILE or CMD \| GREP \<opt\> PATTERN <br> -I : Ignore Case <br> -N : Print line Number | 0.93 |
|
||||
| HTTPGET | In Progress | HTTPGET <ip\|host> [port] <br> -U Url <br> -F UrlFile | 0.93 |
|
||||
| HTTPGET | Working | HTTPGET <ip\|host> [port] <br> -U Url <br> -F UrlFile | 0.93 |
|
||||
| IPCONFIG | Working | -D : Try to get IP address from DHCP <br> -E : Read ETC files <br> -S : Set/Reset TCPIP configuration (-E, then -D if required) | 0.93 |
|
||||
| KILL | Working | KILL \<signal\> PID <br> -0 : No Signal <br> -1 : SIGQUIT <br> -2 : SIGKILL | 0.93 |
|
||||
| LS | Working | -A : Print . & .. <br> -C : Single column listing <br> -F : Single column, includes full path <br> -L : long listing with size/date... <br> -R : Recurse subdirectories | 0.93 |
|
||||
@ -79,17 +79,17 @@ This is the functional specification for A2osX and its system modules, internal
|
||||
| SH | Working | Shell Command Processor<br>(See Internal Shell commands) | 0.93 |
|
||||
| TELNET | Working | TELNET <ip\|host> [port] | 0.93 |
|
||||
| TERM | Testing | TERM \<device\> | 0.93 |
|
||||
| UNPAK | Testing | UNPAK archive | 0.93 |
|
||||
| UNPAK | Working | UNPAK archive | 0.93 |
|
||||
| USERADD | Testing | USERADD username <br> -c Comment : GECOS comment<br> -d HD : Home Directory <br> -p PW : Password <br> -s SH : Shell | 0.93 |
|
||||
| USERDEL | Testing | USERDEL username <br> -r : Force removes files in home directory | 0.93 |
|
||||
| WC | Testing | WC File(s) (*,? wildcards allowed) <br> -C: Continue on error<br> -R: Recurse Subdirectories<br> -M: Print CHAR counts<br> -L: Print LINE counts<br> -W: Print WORD counts | 0.93 |
|
||||
| WHO | Testing | List Users Online | 0.93 |
|
||||
| WC | Working | WC File(s) (*,? wildcards allowed) <br> -C: Continue on error<br> -R: Recurse Subdirectories<br> -M: Print CHAR counts<br> -L: Print LINE counts<br> -W: Print WORD counts | 0.93 |
|
||||
| WHO | Working | List Users Online | 0.93 |
|
||||
|
||||
## Internal Shell commands:
|
||||
|
||||
| Name | Status | Comment |
|
||||
| ---- | ------ | ------- |
|
||||
| \<condition\> | Working |[ -D direxists ] <br> [ -E fileordirexists ] <br> [ -F fileexists ]<br> [ -I $VAR variable is an integer ] <br> [ -N $VAR variable is not empty ] <br> [ -Z $VAR variable is empty ] <br> [ string1 = string2 ] <br> [ string1 != string2 ] <br> [ string1 .< string2 ] <br> [ string1 <= string2 ] <br> [ string1 .> string2 ] <br> [ string1 >= string2 ] <br> [ int32 -eq int32 ] <br> [ int32 -ne int32 ] <br> [ int32 -lt int32 ] <br> [ int32 -le int32 ] <br> [ int32 -gt int32 ] <br> [ int32 -ge int32 ] |
|
||||
| \<condition\> | Working |[ -D direxists ] <br> [ -E fileordirexists ] <br> [ -F fileexists ]<br> [ -I isaninteger ] <br> [ -N $VAR variable is not empty ] <br> [ -Z $VAR variable is empty ] <br> [ string1 = string2 ] <br> [ string1 != string2 ] <br> [ string1 .< string2 ] <br> [ string1 <= string2 ] <br> [ string1 .> string2 ] <br> [ string1 >= string2 ] <br> [ int32 -eq int32 ] <br> [ int32 -ne int32 ] <br> [ int32 -lt int32 ] <br> [ int32 -le int32 ] <br> [ int32 -gt int32 ] <br> [ int32 -ge int32 ] |
|
||||
| \<expression\> | Working | \<value\> [\<op\> \<value\>] ... |
|
||||
| \<op\> | Working | \+ : signed int32 add <br> \- : signed int32 subtract <br> \* : signed int32 multiply<br> / : signed int32 divide <br> mod : signed int32 modulo |
|
||||
| \<value\> | Working | $VAR \| string \| "string with SPACE" \| 123 \| -456 |
|
||||
|
25
EXAMPLES/FMENU.txt
Normal file
25
EXAMPLES/FMENU.txt
Normal file
@ -0,0 +1,25 @@
|
||||
NEW
|
||||
PREFIX
|
||||
AUTO 4,1
|
||||
MAN
|
||||
#!/BIN/SH
|
||||
#
|
||||
# This script defines a Menu Function that can be used
|
||||
# in multiple scripts.
|
||||
#
|
||||
# Load this function by calling . FMENU
|
||||
#
|
||||
# Call the Function with CALL A2MENU RVar NumMI T1 M1 M2 M3 M4 M5 M6 M7 M8 M9
|
||||
# where RVar is the name of the variable you want the menu choice placed into
|
||||
# NumMI is the Number of Menu Items you want to display (max 9)
|
||||
# T1 is the menu Title
|
||||
# M1 ... M9 are the available menu choices
|
||||
#
|
||||
FUNCTION A2MENU
|
||||
{
|
||||
# Start of A2MENU Code
|
||||
ECHO "\f
|
||||
|
||||
}
|
||||
# End of FMENU
|
||||
TEXT /MAKE/USR/SHARE/EXAMPLES/FMENU
|
109
EXAMPLES/ORTESTS.txt
Normal file
109
EXAMPLES/ORTESTS.txt
Normal file
@ -0,0 +1,109 @@
|
||||
NEW
|
||||
PREFIX
|
||||
AUTO 4,1
|
||||
#!/BIN/SH
|
||||
#
|
||||
# Complex OR OR Tests
|
||||
#
|
||||
SET A = 1
|
||||
SET B = 2
|
||||
SET C = 3
|
||||
SET D = 4
|
||||
ECHO -N "TRUE OR TRUE OR TRUE OR TRUE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -eq 2 ] OR [ $C -eq 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR TRUE OR TRUE OR FALSE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -eq 2 ] OR [ $C -eq 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR TRUE OR FALSE OR TRUE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -eq 2 ] OR [ $C -ne 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR TRUE OR FALSE OR FALSE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -eq 2 ] OR [ $C -ne 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR FALSE OR TRUE OR TRUE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -ne 2 ] OR [ $C -eq 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR FALSE OR TRUE OR FALSE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -ne 2 ] OR [ $C -eq 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR FALSE OR FALSE OR TRUE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -ne 2 ] OR [ $C -ne 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "TRUE OR FALSE OR FALSE OR FALSE ---> "
|
||||
IF [ $A -eq 1 ] OR [ $B -ne 2 ] OR [ $C -ne 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR TRUE OR TRUE OR TRUE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -eq 2 ] OR [ $C -eq 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR TRUE OR TRUE OR FALSE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -eq 2 ] OR [ $C -eq 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR TRUE OR FALSE OR TRUE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -eq 2 ] OR [ $C -ne 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR TRUE OR FALSE OR FALSE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -eq 2 ] OR [ $C -ne 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR FALSE OR TRUE OR TRUE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -ne 2 ] OR [ $C -eq 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR FALSE OR TRUE OR FALSE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -ne 2 ] OR [ $C -eq 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR FALSE OR FALSE OR TRUE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -ne 2 ] OR [ $C -ne 3 ] OR [ $D -eq 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
ECHO -N "FALSE OR FALSE OR FALSE OR FALSE ---> "
|
||||
IF [ $A -ne 1 ] OR [ $B -ne 2 ] OR [ $C -ne 3 ] OR [ $D -ne 4 ]
|
||||
ECHO TRUE
|
||||
ELSE
|
||||
ECHO FALSE
|
||||
FI
|
||||
MAN
|
||||
TEXT /MAKE/USR/SHARE/EXAMPLES/ORTESTS
|
26
EXAMPLES/SWITCHDEMO.txt
Normal file
26
EXAMPLES/SWITCHDEMO.txt
Normal file
@ -0,0 +1,26 @@
|
||||
NEW
|
||||
PREFIX
|
||||
AUTO 4,1
|
||||
#!/BIN/SH
|
||||
#
|
||||
# Script to Demonstrate the SWITCH Command
|
||||
#
|
||||
READ -P "VAR:" VAR
|
||||
ECHO \r\n
|
||||
SWITCH $VAR
|
||||
CASE 1
|
||||
ECHO CASE IS 1
|
||||
BREAK
|
||||
CASE 2
|
||||
CASE 3
|
||||
ECHO CASE IS 2 OR 3
|
||||
BREAK
|
||||
DEFAULT
|
||||
ECHO CASE IS SOMETHING ELSE : $VAR
|
||||
END
|
||||
ECHO ...
|
||||
EXIT $VAR
|
||||
|
||||
|
||||
MAN
|
||||
TEXT /MAKE/USR/SHARE/EXAMPLES/SWITCHDEMO
|
Loading…
Reference in New Issue
Block a user