2019-03-24 00:36:51 +00:00
# A2osX Shell Developers Guide
2019-10-24 14:44:59 +00:00
### Updated October 22, 2019
2019-03-24 00:36:51 +00:00
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 (BINs or executables) commands. Internal commands include CD (change directory), MD (make directory), DATE, TIME, etc. External commands include CP (copy), RM (remove), CAT (display file contents), TELNET, etc.
It should be noted, that it is possible to create and execute short scripts right on the interactive command line (these are run once and not saved like true scripts). An example
2019-05-28 20:45:43 +00:00
## The A2osX Shell (SH)
2019-03-24 00:36:51 +00:00
### Variables
Variable overflow strings and ints
Ints only no real num it just ignore
The 32-bit int data type can hold integer values in the range of − 2,147,483,648 to 2,147,483,647. If you add to or subtract from INTs that would cause a RANGE error, you actually get a result that wraps around the range, so if you add 1 to 2,147,483,647 you will get − 2,147,483,648.
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.
The Shell
2019-05-28 20:45:43 +00:00
Interacting with the Shell.
2019-03-24 00:36:51 +00:00
Special Keys
2019-05-28 20:45:43 +00:00
| Key | Usage |
| -- | -- |
| BACKSPACE | Deletes character under the cursor. Note this key does not exist on Apple keyboards, but may on terminals connected via an SSC or through a Telnet Session |
| DELETE | Deletes character to left of cursor and moves cursor/rest of line to the left |
| Control-C | Erases entire command line |
2019-10-25 02:38:34 +00:00
| Control-D | Exits Shell and if the top most Shell logs you out of your session |
2019-05-28 20:45:43 +00:00
| Control-Z | Deletes character under the cursor |
| Up Arrow | Displays previous command from history. Multiple Up Arrows scrolls progressively through history |
| Down Arrow | Displays next command from history. Multiple Down Arrows scrolls progressively through history |
| Left Arrow | Moves cursor to the left to edit current command |
| Right Arrow | Moves cursor to the right to edit current command |
| 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 |
2019-03-24 00:36:51 +00:00
Internal Commands
2019-05-28 20:45:43 +00:00
2019-03-24 00:36:51 +00:00
External Commands
2019-05-28 20:45:43 +00:00
2019-03-24 00:36:51 +00:00
Variables
2019-05-28 20:45:43 +00:00
2019-03-24 00:36:51 +00:00
Special Variables
2019-05-28 20:45:43 +00:00
2019-03-24 00:36:51 +00:00
Scripts
2019-05-28 20:45:43 +00:00
2019-10-25 02:38:34 +00:00
Calling other scripts
calling scripts with . (dot space) before script name from within a script
loading functions this way
2019-03-24 00:36:51 +00:00
Redirection
## Advanced Display Techniques
VT100 Codes
\f Clear Screen
\b backspace
\n newline
\r return (beginning of line with no new line)
\eM Scroll Screen Down 1 Line
\eD Scroll the Screen Up 1 Line
\ec Clear Screen
\e[05;15H Move cursor to row 5 and col 15
\e[H Move to home position (0,0)
\e[K Clear from cursor to end of line
\e[1K Clear from cursor to beginning of line
\e[2K Clear line
Plus Colors
###Examples
IFTTT Tweet using HTTPGET
2019-05-28 20:45:43 +00:00
Also look at Microsoft Flow and Integromat and Automate.io
2019-03-24 00:36:51 +00:00
where [ exp ] and [ condition ] allow to detail operators....
2019-04-12 14:53:00 +00:00
anywhere you can have [ exp ] you can have ![ exp ] which means NOT exp.
while ![ $total -eq 0 ]
loop
is the same thing as
while [ $total -ne 0 ]
loop
Just like
IF [ A -GT 5 ]
DO X
ELSE
DO Y
FI
is the same as
IF ![ A -LE 5 ]
DO Y
ELSE
DO X
FI
Notice that the DO X and DO Y logic is swapped between the two cases.
2019-03-24 00:36:51 +00:00
## Internal Shell commands:
| Name | Status | Comment |
| ---- | ------ | ------- |
| \<value\> | Working | $VAR \| string \| "string with SPACE" \| 123 \| -456 |
| \<expression\> | Working | \<value\> [\<op\> \<value\>] ... |
2019-04-01 06:07:56 +00:00
| \<op\> | Working | \+ signed int32 add < br > \- signed int32 sub < br > \* < br > / < br > mod |
2019-04-12 14:53:00 +00:00
| \<condition\> | Working |[ -D direxists ] < br > [ -E fileordirexists ] < br > [ -F fileexists ]< 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 ]|
2019-03-24 00:36:51 +00:00
| BREAK | Working | Exit CASE of SWITCH |
2019-04-01 15:24:01 +00:00
| CALL | Working | CALL function < arg > ... |
2019-03-24 00:36:51 +00:00
| CASE | Working | CASE < expression > |
| CD | Working | CD path or relative path |
2019-04-04 15:44:20 +00:00
| .. | Working | CD .. |
2019-03-24 00:36:51 +00:00
| DATE | Working | |
| DEFAULT | Working | Default CASE for SWITCH |
| ECHO | Working | \b,\e,\f,\n,\\\ and \\% supported < br > -N : Suppress \r\n |
| ELSE | Working | Optional branch for IF block |
| END | Working | End of SWITCH Statement |
2019-04-04 15:44:20 +00:00
| EXIT | Working | exit function, script or shell |
2019-03-24 00:36:51 +00:00
| FI | Working | Terminator for IF block |
2019-10-14 17:47:57 +00:00
| FUNCTION | Working | FUNCTION function_name { < br > \<body\> < br > } |
2019-04-12 14:53:00 +00:00
| IF | Working | [ \<condition\> ] < br > ![ \<condition\> ]|
2019-03-24 00:36:51 +00:00
| LOOP | Working | Terminator for WHILE block |
| MD | Working | MD path or relative path < br > Create a directory |
| NOHUP | Working | Start a process with PPID=PS0 (Daemon) |
| PAUSE | Working | Wait until CR |
| POPD | Working | Restore previously saved working directory |
| PUSHD | Working | Save actual working directory < br > PUSHD \<dir\> do also a CD to \<dir\> |
| PWD | Working | Print Working Directory |
| RD | Working | Delete an empty directory |
2019-08-15 12:48:58 +00:00
| READ | Working | -S : no echo (password) < br > -P : "prompt message" < br > -N maxchar |
2019-03-24 00:36:51 +00:00
| REN | Working | Rename a file, directory or volume |
2019-04-04 15:44:20 +00:00
| 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 |
2019-03-24 00:36:51 +00:00
| SHIFT | Working | Remove $1 from cmd line |
| SLEEP | Working | Wait \<count\> 10th sec |
| SWITCH | Working | SWITCH < expression > |
| TIME | Working | |
| WHILE | Working | [ \<condition\> ] |
## Shell variables:
| Name | Status | Comment |
| ---- | ------ | ------- |
| $0 | Working | Command Full Path |
| $1-$9 | Working | Arg[n] |
| $* | Working | All Args |
| $# | Working | Arg Count |
| $? | Working | Return Code |
| $@ | Working | Parent PID |
| $$ | Working | PID |
| $! | Working | Child PID |
| $UID | Working | PS Owner UID |
| $PWD | Working | Working Directory |
note : '$VAR' does NOT expand Variable
## Shell I/O control/redirection:
| Token | Status | Comment |
| ---- | ------ | ------- |
| . | Working | use same env |
| & | Working | start proc |
| \| | Working | pipe |
| < | Working | StdIn redirection |
| > | Working | StdOut redirection |
| >> | Working | Append StdOut |
| 1>> | Working | |
| 1> | Working | |
| 2>> | Working | StdErr redirection |
| 2> | Working | |
2019-04-07 02:20:39 +00:00
## Stuff to work on
if [] & & [] is AND
if [] || [] is OR
2019-10-14 17:47:57 +00:00
### functions
if you SET -F, it will discard ALL previously learnt FUNC in the current SH context
if . FUNCS1 file add 3
then . FUNCS2 file add 2
all 5 are available until an set -X is met
if you launch . MYFILE1, the code within MYFILE1 can CALL all 5 functions
but MYFILE1 (wthout dot) will run in a separate SH process, so no access to the 5 functions known by parent SH
functions bodies are stored in AUX ram
so you can put around 30k of code in AUX ram then do a short MYFILE1 that calls a lot of FUNC in AUX
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)
2019-04-07 02:20:39 +00:00
* DIV/MOD
2019-04-14 15:45:02 +00:00
## License
A2osX is licensed under the GNU General Pulic License.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The full A2osX license can be found ** [Here ](../LICENSE )**.
2019-04-14 01:13:06 +00:00
## Copyright
Copyright 2015 - 2019, Remy Gibert and the A2osX contributors.