3 <title>The NewOS Operating System: Docs
</title>
5 <body BGCOLOR=
"#FFFFFF">
7 <h1 align=
"center">NewOS shell manual
<br>Version
0.2-pre
1</h1>
13 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
15 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
16 <center><h3>Contents
</h3></center>
18 <li><a href=
"#What_is_missing">What is missing
</a></li>
19 <li><a href=
"#Running_a_shell_script">The shell
</a></li>
21 <li><a href=
"#Running_a_shell_script">Running a shell script
</a>
23 <li><a href=
"#Introduction">Introduction
</a></li>
24 <li><a href=
"#Variables">Variables
</a></li>
26 <li><a href=
"#Variable_Syntax">Syntax
</a></li>
27 <li><a href=
"#Strings">Numbers and Strings
</a></li>
28 <li><a href=
"#Build_in_variables">Build in variables
</a></li>
30 <li><a href=
"#Operators">Operators
</a></li>
31 <li><a href=
"#Functions">Functions
</a></li>
33 <li><a href=
"#exec_function">exec
</a></li>
34 <li><a href=
"#casting">type casting
</a></li>
36 <li><a href=
"#Statements">Statements
</a></li>
38 <li><a href=
"#Comments">Comments
</a></li>
39 <li><a href=
"#exec">exec
</a></li>
40 <li><a href=
"#exit">exit
</a></li>
41 <li><a href=
"#goto">goto
</a></li>
42 <li><a href=
"#if">if
</a></li>
43 <li><a href=
"#labels">label
</a></li>
52 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
54 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
55 <a name=
"What_is_missing"></a>
56 <center><h3>What is missing
</h3></center>
57 The following features are missing but are added in the next release:
<br>
60 <li>Output redirection of 'echo' statement
</li>
62 <li>not operator?
</li>
71 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
73 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
74 <a name=
"The_shell"></a>
75 <center><h3>The shell
</h3></center>
76 <b>Command line options
</b><br><br>
77 shell [-s] [
<script_name
> <arguments
>]
<br><br>
78 When the
<script_name
> is given as parameters the shell starts
79 the interpretor and runs the script otherwise the shell starts an
80 interactive session.All options before
the script name are handled
81 as shell parameters. An option is everything which starts with a '-'.
<br>
82 The script name is placed in the variable $p0 and the flowing
<arguments
>
83 are
placed in $p1..$p??. $argc contains the number of arguments. The
84 path in $path is used as search path for the script. The $path value is
85 hard coded in the shell.
<br>
86 By default the shell exits after when
the script ends, but with
87 the '-s' option the shell starts an interactive session.
<br>
94 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
96 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
97 <a name=
"Introduction"></a>
98 <center><h3>Script language Introduction
</h3></center>
99 The shell script language has the following features:
<br>
101 <li>Case sensitive
</li>
102 <li>Identifier names:
<br>
103 Starts with a alphabetic symbol and a number,alphabetic or a '_' symbols
105 Variables :$
<identifier_name
><br>
106 Label :
<identifier_name
>:
118 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
120 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
121 <a name=
"Variables"></a>
122 <center><h3>Variables
</h3></center>
123 <a name=
"Variable_Syntax"></a>
125 The syntax of a variable name is $
<Identifier
>.
<br>
126 $a=
<value
> , defines a variable.
<br>
127 A variable can't be removed yet.
<br>
128 When a new script is started the variables are not shared with the new process.
130 <a name=
"Strings"></a>
131 <b>Numbers and Strings
</b><br>
132 Numbers are stored and handled as
64 bit signed integers
<br>
134 Strings can start and end with single or double quotes. In double quoted strings
135 variables (starting with a $) are substituted by their value.
<br>
136 The shell variables doesn't have a type, it can contain a string or a number.
<br>
137 It is not possible to mix strings and numbers in formula's. More info:
138 <a href=
"#Operators">Operators
</a>
139 When a value is a string or a number, depends on how they are defined and not
140 on their contents:
<br>
142 $a='
1',
$a contains a string.
<br>
144 $b=
1 ,
$b contains a number
<br>
146 $c=$a+$b this fails because $a contains a string and $b contains a number.
<br>
148 <a name=
"Build_in_variables"></a>
149 <b>Built in variables
</b><br>
150 <table cellpadding=
"2" cellspacing=
"2" border=
"1" width=
"100%">
152 <td valign=
"Top">$path
</td>
153 <td valign=
"Top">Search path for programs
</td>
156 <td valign=
"Top">$argc
</td>
157 <td valign=
"Top">number of arguments
</td>
160 <td valign=
"Top">$p0
</td>
161 <td valign=
"Top">Parameter
0, which is the script filename
</td>
164 <td valign=
"Top">$p1...p
<no
></td>
165 <td valign=
"Top">Script parameters
</td>
169 Parameters are stored as strings. When parameters are used with numbers
170 they must be cast:
<br>
172 <b>if(number($p1) ==
1) goto the_end
</b><br>
174 <b>if($p1 ==
"1") goto the_end
</b><br>
175 following will fail:
<br>
176 <b>if($p1 ==
1) goto the_end
</b><br>
183 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
185 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
186 <a name=
"Operators"></a>
187 <center><h3>Operators
</h3></center>
188 In the NewOS shell script language it is possible to write formulas the
189 same way as in most modern programming languages.
<br>
190 The shell can handle the following operators:
<br>
191 +, -, /, *, =,
<=, =, =
>,
<,
>, !=, ==
<br>
193 All operators can be used with numerical values, and are calculated
195 String values can only be used with the compare operators(=,
<=,=
> etc..)
196 and the load operator(=).
<br>
197 The compare operator returns a value
1 or
0 for true of false
<br>
198 It is not possible to mix strings and numbers in formulas, the program fails with
199 an error messages. But a string can be
<a href=
"cast">cast
</a> into a number
201 This is neccesary because some operator handle strings different as numbers :
<br>
203 <li>10>2 is true
</li>
204 <li>"10">"2" is false
</li>
212 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
214 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
215 <a name=
"Functions"></a>
216 <center><h3>Functions
</h3></center>
217 <a name=
"exec_function"></a>
222 <b>exec(
</b><string expression
>)
<br>
224 <u>description:
</u><br>
226 The exec function starts program in
<string expression
> (which is
227 the program name and parameters), waits until the process terminates and returns
228 the exit value. When filename is not found the execution of the script terminates
229 with an error message.
<br>
230 This 'exec' function is using the
path in $path as search path.
<br>
233 $
program=
"shell $p0"<br>
234 $result=exec($program)
<br>
238 $result=exec(
"shell /boot/bin/initX")
<br>
241 <a name=
"casting"></a>
242 <b>type casting: number() and string()
</b><br>
245 number(
<expression
>)
<br>
246 string(
<expression
>)
<br>
248 The shell makes a distinction between strings
and number. '
1' is a
249 string all though it contains a number.
<br>
250 <b>number('
1')
</b> casts the string into a number.
<br>
252 <b>string
</b>converts a number to a string.
<br>
257 if($p1==$a+
1) goto somewhere
<br>
259 Fails because
parameters($p1) is always a string, this should be:
<br>
262 if($p1==string($a+
1)) goto somewhere
<br>
267 if(number($p1)==$a+
1) goto somewhere
<br>
269 The difference between the last
2 examples is that the 'number' cast fails
270 when $p1 doesn't contain a valid number.
277 <table border=
"0" width=
"100%" bgcolor=
"#E8E8E8">
279 <td width=
"100%" height=
"100%" valign=
"top" align=
"left">
280 <a name=
"Statements"></a>
281 <center><h3>Statements
</h3></center>
282 <a name=
"Comments"></a>
284 Comments always start with the '#' character end at the line end.
<br>
290 [
<b>exec
</b>]
<program_name
> <options
><br>
292 <u>description:
</u><br>
293 This command starts another process and executes a binary program.
<br>
294 A program can also started by just using the
<program_name
>. The exec
295 statement is optional but when the
<program_name
> is a detemened by
296 a variable the 'exec' statements must be used.
<br>
298 The exec statement can have the following 'options':
<br>
300 <li>'
&' at the end: The shell doesn't wait until the process ends
</li>
301 <li>Output redirection
</li>
304 $texteditor =
"word"<br>
305 if($no_ms) $
texteditor=
"vi"<br>
306 exec $texteditor $p1
<br>
311 <b>exit
</b> [(
<expression
>)]
<br>
313 <u>description:
</u><br>
314 The program exits with exit value
<expression
>.
<br>
316 When script is started without the -s option the shell always exits
317 after the script ends.
<br>
318 When no expression is given, the exit code is
0.
<br>
319 Expression must be a number.
<br>
325 <b>goto
</b> <label_name
><br>
327 <u>description:
</u><br>
328 After the 'goto' statement the program execution starts after the label
329 <label_name
>.
<br>
330 When label can't be found, the program fails with 'label not found' error.
<br>
336 <b>if
</b>(
<expression
>)
<statement
><br>
338 <u>description:
</u><br>
339 <statement
> is executed when
<expression
> <> 0<br>
340 Only one statement can follow 'if'.
<br>
343 <a name=
"labels"></a>
346 <label_name
>:
<br>
349 The script file is not yet checked for duplicate labels.
356 <table border=
"1" width=
"100%" bgcolor=
"#D9D5FF">
358 <td width=
"100%" height=
"49" valign=
"top" align=
"center"><small><font color=
"#000000">This
359 page copyright
2002 </font></small><font size=
"2">
361 Any questions, comments, gripes, whatever:
362 <a href="mailto:geist@newos.org">geist@newos.org</a></font>