3 Shell

The DINO shell provides an interface between program and user, just as the UNIX shell provides an interface between operating system and user. The DINO shell offers a prompt in the terminal, where commands can be typed in. In essence, the input is parsed, some syntax rules are applied and the command line is broken down into words. The first word is checked against the internal shell commands, if no match is found the command line is passed to the database manager.

3.1 Syntax

Variables

Words beginning with a
$
are interpreted as variables and are replaced with the value of the variable. (see commands
set
and
unset
below).

Recursive Subprompts

An expression enclosed in square brackets is considered a subprompt. It is evaluated first, and the result (return value) of the sub-expression is inserted at the position of the subprompt. Consider the following input:

> expression1 [expression2 arg]

expression2 arg
is treated as a separate command, its result
result2
is inserted in the place of the original subprompt and becomes:

> expression1 result2

The subprompts can be nested (almost) unlimited.

Scripts

A script is called with the
@
sign, followed by the filename. Additional words are interpreted as parameters and are passed as variables to the script, accessible as
$1
,
$2
...
$n
(n = number of arguments).

Syntax: @scriptfile [param1 ...]

Comments

Two slashes denote a comment (C++ style) and can appear anywhere in the line, with the rest of the line (up to newline) treated as a comment.

Example: // this is a comment

Character Protection

Use the backslash to protect the following character from being interpreted by the shell parser. This is useful when continuing a line in a script or literally inserting a $ or square bracket.

Example: // a line can be continued if the \
last character before newline is '\'

Splitting Input

Multiple command lines can be entered on a single line when separated with a semicolon:

Syntax: command1 arg1 ; command2 arg2 ; command3 arg3

3.2 Shell Commands

Writing Output to the Terminal or a File

The command
echo
prints all of its arguments to the terminal. The output can be redirected into a file with
>
(write) or
>>
(append):

Syntax: echo WORD1 [WORD2 ...] [>[>] file.out]

Variables and Aliases

Variables are defined and removed with
set
and
unset
. The command
var
will list all currently defined variables with their values.

Syntax: set VAR VALUE
unset VAR [VAR ...]

An alias is a special form of variable. It is defined with
alias
and removed with
unalias
.

Syntax: alias ALIAS EXPRESSION
unalias ALIAS

If the first word on the command line (or the first word in a subprompt!) matches
ALIAS
, it will be replaced by
EXPRESSION
(which can consist of multiple words).
alias
by itself will list all defined aliases.

Pausing Script Execution

In a script, the command
pause
will stop execution until a key is pressed. If the key is ESC, script execution is stopped.

Stopping Script Execution

In a script, the command
break
will discontinue script execution and return one level up, either to the calling script or the command prompt.

Executing a Unix Command

Use
system
or
!
to execute a command in a unix shell

Example: system gimp pic1.png
!ls -l

Exiting

3.3 RPN Stack

The commands
push
,
pop
,
peek
,
opr
,
clear
,
dup
and
show
manipulate the arithmetic RPN stack2.
push
moves all arguments onto the stack (from left to right).
pop
retrieves values from the stack, optionally into supplied variable names.
peek
returns the topmost value without removing it from the stack.
opr
takes a list of operator which are applied (left to right) to the stack.
clear
empties the stack.
dup
duplicates the top value.
show
displays the complete stack.

2.In a nutshell: In RPN (Reverse Polish Notation), a stack is filled with values, and an operator is called that uses the topmost value (unary op, e.g. sqrt) or the two topmost values (binary op, e.g. +), placing the value back on the stack. A simple arithmetic expression as 1+1 becomes 1 1 +, a more complex as (1+2)*(4/5+6) becomes 1 2 + 4 5 / 6 + *. People used to the HP calculators or programming PS will be familiar with this approach.