bs(1)bs(1)NAMEbs - a compiler/interpreter for modest-sized programs
SYNOPSIS
[file [args]]
DESCRIPTION
is a remote descendant of BASIC and SNOBOL4 with some C language added.
is designed for programming tasks where program development time is as
important as the resulting speed of execution. Formalities of data
declaration and file/process manipulation are minimized. Line-at-a-
time debugging, the and statements, and useful run-time error messages
all simplify program testing. Furthermore, incomplete programs can be
debugged; inner functions can be tested before outer functions have
been written, and vice versa.
If file is specified on the command-line, it is used for input before
any input is taken from the keyboard. By default, statements read from
file are compiled for later execution. Likewise, statements entered
from the keyboard are normally executed immediately (see and below).
Unless the final operation is assignment, the result of an immediate
expression statement is printed.
programs are made up of input lines. If the last character on a line
is a the line is continued. accepts lines of the following form:
statement
label statement
A label is a name (see below) followed by a colon. A label and a vari‐
able can have the same name.
A statement is either an expression or a keyword followed by zero or
more expressions. Some keywords and are always executed as they are
compiled.
Statement Syntax:
expression The expression is executed for its side effects (value,
assignment, or function call). The details of expres‐
sions follow the description of statement types below.
exits from the innermost
loop.
Clears the symbol table and compiled statements.
is executed immediately.
Succeeding statements are compiled
(overrides the immediate execution default). The
optional expression is evaluated and used as a file name
for further input. A is associated with this latter
case. is executed immediately.
transfers to the loop-continuation of the current
loop.
The name and current value of every non-local variable is printed.
Optionally, only the named variable is reported. After
an error or interrupt, the number of the last statement
is displayed. The user-function trace is displayed
after an error or that occurred in a function.
A call is made to
the editor selected by the environment variable if it is
present, or ed(1) if is undefined or null. If the file
argument is present on the command line, file is passed
to the editor as the file to edit (otherwise no file
name is used). Upon exiting the editor, a statement
(and associated is executed giving that file name as its
argument.
Return to system level.
The expression is returned as process status.
Change to immediate execution mode (an interrupt has a similar effect).
This statement does not cause stored statements to exe‐
cute (see below).
...
...
The statement repeti‐
tively executes a
statement (first
form) or a group of
statements (second
form) under control
of a named variable.
The variable takes on
the value of the
first expression,
then is incremented
by one on each loop,
not to exceed the
value of the second
expression. The
third and fourth
forms require three
expressions separated
by commas. The first
of these is the ini‐
tialization, the sec‐
ond is the test (true
to continue), and the
third is the loop-
continuation action
(normally an incre‐
ment).
...
defines the function name,
arguments,
and local
variables for
a user-written
function. Up
to ten argu‐
ments and
local vari‐
ables are
allowed. Such
names cannot
be arrays, nor
can they be
I/O associ‐
ated. Func‐
tion defini‐
tions cannot
be nested.
Calling an
undefined
function is
permissible;
see function
calls below.
A way to signal the failure
of a user-written function.
See the inter‐
rogation oper‐
ator below.
If interroga‐
tion is not
present,
merely returns
zero. When
interrogation
is active,
transfers to
that expres‐
sion (possibly
by-passing
intermediate
function
returns).
Control is passed
to the inter‐
nally stored
statement with
the matching
label.
sets the input base (radix)
to
n. The only
supported val‐
ues for n are
the constants
(the default),
and Hexadeci‐
mal values
10-15 are
entered as A
leading digit
is required
(i.e., must be
entered as
(and discussed
below) are
executed imme‐
diately.
...
The
state‐
ment
(first
form) or
group
of
state‐
ments
(sec‐
ond
form)
is
exe‐
cuted
if
the
expres‐
sion
eval‐
u‐
ates
to
non-
zero.
The
strings
and
""
(null)
eval‐
u‐
ate
as
zero.
In
the
sec‐
ond
form,
an
optional
pro‐
vides
for
a
sec‐
ond
group
of
state‐
ments
to
be
exe‐
cuted
when
the
first
group
is
not.
The
only
state‐
ment
per‐
mit‐
ted
on
the
same
line
with
an
is
an
only
other
can
be
on
the
same
line
with
a
The
con‐
cate‐
na‐
tion
of
and
into
an
is
sup‐
ported.
Only
a
sin‐
gle
is
required
to
close
an
sequence.
expres‐
sion must
eval‐
u‐
ate
to
a
file
name.
The
file
must
con‐
tain
source
state‐
ments.
Such
state‐
ments
become
part
of
the
pro‐
gram
being
com‐
piled.
state‐
ments
can‐
not
be
nested.
sets the
output
base to n
(see
above).
pro‐
vides
pro‐
gram
con‐
trol
of
inter‐
rupts. In
the
first
form,
con‐
trol
passes
to
the
label
given,
just
as
if
a
had
been
exe‐
cuted
at
the
time
was
exe‐
cuted.
The
effect
of
the
state‐
ment
is
cleared
after
each
inter‐
rupt.
In
the
sec‐
ond
form,
an
inter‐
rupt
causes
to
ter‐
mi‐
nate.
The
expres‐
sion
is
eval‐
u‐
ated
and
the
result
is
passed back
as
the
value
of
a
func‐
tion
call.
If
no
expres‐
sion
is
given,
zero
is
returned.
The
ran‐
dom
num‐
ber
gen‐
er‐
a‐
tor
is
reset. Con‐
trol
is
passed
to
the
first
inter‐
nal
state‐
ment.
If
the
state‐
ment
is
con‐
tained
in
a
file,
it
should
be
the
last
state‐
ment.
Exe‐
cu‐
tion
of
inter‐
nal
state‐
ments
is
stopped. reverts
to
imme‐
di‐
ate
mode.
The state‐
ment
con‐
trols
func‐
tion
trac‐
ing.
If
the
expres‐
sion
is
null
(or
eval‐
u‐
ates
to
zero),
trac‐
ing
is
turned
off.
Oth‐
er‐
wise,
a
record
of
user-
func‐
tion
calls/returns
is
printed.
Each
decre‐
ments
the
expres‐
sion
value.
...
is
sim‐
i‐
lar
to except
that
only
the
con‐
di‐
tional
expres‐
sion
for
loop-
con‐
tin‐
u‐
a‐
tion
is
given.
An
imme‐
di‐
ate
escape
to
the
shell.
This
state‐
ment
is
ignored
(treated
as
a
com‐
ment).
Expres‐
sion
Syn‐
tax:
name A
name
is
used
to
spec‐
ify
a
vari‐
able.
Names
are
com‐
posed
of
a
let‐
ter
(upper‐
case
or
low‐
er‐
case)
option‐
ally
fol‐
lowed
by
let‐
ters
and
dig‐
its.
Only
the
first
six
char‐
ac‐
ters
of
a
name
are
sig‐
nif‐
i‐
cant.
Except
for
names
declared
in
fun
state‐
ments,
all
names
are
global
to
the
pro‐
gram.
Names
can
take
on
numeric
(dou‐
ble
float)
val‐
ues,
string
val‐
ues,
or
can
be
asso‐
ci‐
ated
with
input/out‐
put
(see
the
built-
in
func‐
tion
below).
name
(
[expres‐
sion
[
,
expres‐
sion]
...
]
) Func‐
tions
can
be
called
by
a
name
fol‐
lowed
by
the
argu‐
ments
in
paren‐
the‐
ses
sep‐
a‐
rated
by
com‐
mas.
Except
for
built-
in
func‐
tions
(listed
below),
the
name
must
be
defined
with
a
fun
state‐
ment.
Argu‐
ments
to
func‐
tions
are
passed
by
value.
If
the
func‐
tion
is
unde‐
fined,
the
call
his‐
tory
to
the
call
of
that
func‐
tion
is
printed,
and
a
request
for
a
return
value
(as
an
expres‐
sion)
is
made.
The
result
of
that
expres‐
sion
is
taken
to
be
the
result
of
the
unde‐
fined
func‐
tion.
This
per‐
mits
debug‐
ging
pro‐
grams
where
not
all
the
func‐
tions
are
yet
defined.
The
value
is
read
from
the
cur‐
rent
input
file.
name
[
expres‐
sion
[
,
expres‐
sion
]
...
] This
syn‐
tax
is
used
to
ref‐
er‐
ence
either
arrays
or
tables
(see
built-
in
ta‐
ble
func‐
tions
below).
For
arrays,
each
expres‐
sion
is
trun‐
cated
to
an
inte‐
ger
and
used
as
a
spec‐
i‐
fier
for
the
name.
The
result‐
ing
array
ref‐
er‐
ence
is
syn‐
tac‐
ti‐
cally
iden‐
ti‐
cal
to
a
name;
is
the
same
as
The
trun‐
cated
expres‐
sions
are
restricted
to
val‐
ues
between
0
and
32767.
num‐
ber A
num‐
ber
is
used
to
rep‐
re‐
sent
a
con‐
stant
value.
A
num‐
ber
is
writ‐
ten
in
For‐
tran
style,
and
con‐
tains
dig‐
its,
an
optional
dec‐
i‐
mal
point,
and
pos‐
si‐
bly
a
scale
fac‐
tor
con‐
sist‐
ing
of
an
fol‐
lowed
by
a
pos‐
si‐
bly
signed
expo‐
nent.
string Char‐
ac‐
ter
strings
are
delim‐
ited
by
"
char‐
ac‐
ters.
The
escape
char‐
ac‐
ter
allows
the
dou‐
ble
quote
("),
new-
line
car‐
riage
return
backspace
and
tab
char‐
ac‐
ters
to
appear
in
a
string.
Oth‐
er‐
wise,
stands
for
itself.
(
expres‐
sion
) Paren‐
the‐
ses
are
used
to
alter
the
nor‐
mal
order
of
eval‐
u‐
a‐
tion.
(
expres‐
sion
,
expres‐
sion
[
,
expres‐
sion
...
]
)
[
expres‐
sion
] The
brack‐
eted
expres‐
sion
is
used
as
a
sub‐
script
to
select
a
comma-
sep‐
a‐
rated
expres‐
sion
from
the
paren‐
the‐
sized
list.
List
ele‐
ments
are
num‐
bered
from
the
left,
start‐
ing
at
zero.
The
expres‐
sion:
has
the
value
if
the
com‐
par‐
i‐
son
is
true.
The
inter‐
ro‐
ga‐
tion
oper‐
a‐
tor tests
for
the
suc‐
cess
of
the
expres‐
sion
rather
than
its
value.
At
the
moment,
it
is
use‐
ful
for
test‐
ing
end-
of-
file
(see
exam‐
ples
in
the
Pro‐
gram‐
ming
Tips
sec‐
tion
below),
the
result
of
the
built-
in
func‐
tion,
and
for
check‐
ing
the
return
from
user-
writ‐
ten
func‐
tions
(see
An
inter‐
ro‐
ga‐
tion
``trap''
(end-
of-
file,
etc.)
causes
an
imme‐
di‐
ate
trans‐
fer
to
the
most
recent
inter‐
ro‐
ga‐
tion,
pos‐
si‐
bly
skip‐
ping
assign‐
ment
state‐
ments
or
inter‐
ven‐
ing
func‐
tion
lev‐
els.
The
result
is
the
nega‐
tion
of
the
expres‐
sion.
Incre‐
ments
the
value
of
the
vari‐
able
(or
array
ref‐
er‐
ence). The
result
is
the
new
value.
Decre‐
ments
the
value
of
the
vari‐
able. The
result
is
the
new
value.
The
log‐
i‐
cal
nega‐
tion
of
the
expres‐
sion. Watch
out
for
the
shell
escape
com‐
mand.
expres‐
sion oper‐
a‐
tor
expres‐
sion
Com‐
mon
func‐
tions
of
two
argu‐
ments
are
abbre‐
vi‐
ated
by
the
two
argu‐
ments
sep‐
a‐
rated
by
an
oper‐
a‐
tor
denot‐
ing
the
func‐
tion.
Except
for
the
assign‐
ment,
con‐
cate‐
na‐
tion,
and
rela‐
tional
oper‐
a‐
tors,
both
op‐
er‐
ands
are
con‐
verted
to
numeric
form
before
the
func‐
tion
is
applied.
Binary
Oper‐
a‐
tors
(in
increas‐
ing
prece‐
dence):
is
the
assign‐
ment
oper‐
a‐
tor. The
left
op‐
er‐
and
must
be
a
name
or
an
array
ele‐
ment.
The
result
is
the
right
op‐
er‐
and.
Assign‐
ment
binds
right
to
left,
all
other
oper‐
a‐
tors
bind
left
to
right.
(under‐
score) is
the
con‐
cate‐
na‐
tion
oper‐
a‐
tor.
(log‐
i‐
cal AND)
has
result
zero
if
either
of
its
argu‐
ments
are
zero.
It
has
result
one
if
both
of
its
argu‐
ments
are
non-
zero;
(log‐
i‐
cal
OR)
has
result
zero
if
both
of
its
argu‐
ments
are
zero.
It
has
result
one
if
either
of
its
argu‐
ments
is
non-
zero.
Both
oper‐
a‐
tors
treat
a
null
string
as
a
zero.
The
rela‐
tional
oper‐
a‐
tors less
than,
less
than
or
equal,
greater
than,
greater
than
or
equal,
equal
to,
not
equal
to)
return
one
if
their
argu‐
ments
are
in
the
spec‐
i‐
fied
rela‐
tion,
or
return
zero
oth‐
er‐
wise.
Rela‐
tional
oper‐
a‐
tors
at
the
same
level
extend
as
fol‐
lows:
is
equiv‐
a‐
lent
to
a>b
&
b>c.
A
string
com‐
par‐
i‐
son
is
made
if
both
op‐
er‐
ands
are
strings.
Add
and
sub‐
tract.
Mul‐
ti‐
ply,
divide,
and
remain‐
der.
Expo‐
nen‐
ti‐
a‐
tion.
Built-
in
Func‐
tions:
is
the
value
of
the i-
th
actual
param‐
e‐
ter
on
the
cur‐
rent
level
of
func‐
tion
call.
At
level
zero,
arg
returns
the
i-
th
com‐
mand-
line
argu‐
ment
(arg(0)
returns
returns
the
num‐
ber
of
argu‐
ments
passed. At
level
zero,
the
com‐
mand
argu‐
ment
count
is
returned.
is
the
abso‐
lute
value
of x.
is
the
arc‐
tan‐
gent
of x.
Its
value
is
between
−π/2
and
π/2.
returns the
small‐
est
inte‐
ger
not
less
than
x.
is
the
cosine
of x
(radi‐
ans).
is
the
expo‐
nen‐
tial
func‐
tion
of x.
returns the
largest
inte‐
ger
not
greater
than
x.
is
the
nat‐
u‐
ral
log‐
a‐
rithm
of x.
is
a
uni‐
formly
dis‐
trib‐
uted
ran‐
dom num‐
ber
between
zero
and
one.
is
the
sine
of x
(radi‐
ans).
is
the
square
root
of x.
the
size
(length
in
bytes)
of s
is
returned.
returns
the
for‐
mat‐
ted
value
of a.
f
is
assumed
to
be
a
for‐
mat
spec‐
i‐
fi‐
ca‐
tion
in
the
style
of
printf(3S).
Only
the
and
types
are
safe.
Since
it
is
not
always
pos‐
si‐
ble
to
know
whether
is
a
num‐
ber
or
a
string
when
the
call
is
coded,
coerc‐
ing
to
the
type
required
by
by
either
adding
zero
(for
or
for‐
mat)
or
con‐
cate‐
nat‐
ing
the
null
string
(for
for‐
mat)
should
be
con‐
sid‐
ered.
returns
the
num‐
ber
of
the
first
posi‐
tion
in x
that
any
of
the
char‐
ac‐
ters
from
y
matches.
No
match
yields
zero.
Trans‐
lates
char‐
ac‐
ters
of
the
source s
from
match‐
ing
char‐
ac‐
ters
in
f
to
a
char‐
ac‐
ter
in
the
same
posi‐
tion
in
t.
Source
char‐
ac‐
ters
that
do
not
appear
in
f
are
copied
to
the
result.
If
the
string
f
is
longer
than
t,
source
char‐
ac‐
ters
that
match
in
the
excess
por‐
tion
of
f
do
not
appear
in
the
result.
returns
the
sub-
string
of
s
defined
by
the
start‐
ing
posi‐
tion
and
width.
The pat‐
tern
is
a
reg‐
u‐
lar
expres‐
sion
accord‐
ing
to
the
Basic
Reg‐
u‐
lar
Expres‐
sion
def‐
i‐
ni‐
tion
(see
reg‐
exp(5)).
returns
the
n-
th
(1
<=
n
<=
10)
sub‐
string
of
the
sub‐
ject
that
occurred
between
pairs
of
the
pat‐
tern
sym‐
bols
and
for
the
most
recent
call
to
match.
To
suc‐
ceed,
pat‐
terns
must
match
the
begin‐
ning
of
the
string
(as
if
all
pat‐
terns
began
with
The
func‐
tion
returns
the
num‐
ber
of
char‐
ac‐
ters
matched.
For
exam‐
ple:
name argu‐
ment
must
be
a
vari‐
able
name
(passed
as
a
string).
For
the
the
file
argu‐
ment
can
be:
1. a
0
(zero),
1,
or
2
rep‐
re‐
sent‐
ing
stan‐
dard
input,
out‐
put,
or
error
out‐
put,
respec‐
tively;
2. a
string
rep‐
re‐
sent‐
ing
a
file
name;
or
3. a
string
begin‐
ning
with
an
rep‐
re‐
sent‐
ing
a
com‐
mand
to
be
exe‐
cuted
(via
The
func‐
tion
argu‐
ment
must
be
either
(read),
(write),
(write
with‐
out
new-
line),
or
(append).
After
a
name
reverts
to
being
an
ordi‐
nary
vari‐
able.
If
name
was
a
pipe,
a
is
exe‐
cuted
before
the
close
com‐
pletes
(see
wait(2)).
The
com‐
mand
does
not
do
such
a
wait.
The
ini‐
tial
asso‐
ci‐
a‐
tions
are:
Exam‐
ples
are
given
in
the
fol‐
low‐
ing
sec‐
tion.
exe‐
cutes (see
access(2)).
returns
a
sin‐
gle
char‐
ac‐
ter
file
type
indi‐
ca‐
tion: for
reg‐
u‐
lar
file,
for
FIFO
(i.e.,
named
pipe),
for
direc‐
tory,
for
block
spe‐
cial,
or
for
char‐
ac‐
ter
spe‐
cial.
Tables
A
ta‐
ble
in is
an
asso‐
cia‐
tively
accessed,
sin‐
gle-
dimen‐
sion
array.
``Sub‐
scripts''
(called
keys)
are
strings
(num‐
bers
are
con‐
verted).
The
name
argu‐
ment
must
be
a
vari‐
able
name
(passed
as
a
string).
The
size
argu‐
ment
sets
the
min‐
i‐
mum
num‐
ber
of
ele‐
ments
to
be
allo‐
cated.
prints
an
error
mes‐
sage
and
stops
on
ta‐
ble
over‐
flow.
The
result
of
ta‐
ble
is
name.
The func‐
tion
accesses
ta‐
ble
ele‐
ments
sequen‐
tially
(in
nor‐
mal
use,
there
is
no
orderly
pro‐
gres‐
sion
of
key
val‐
ues).
Where
the
func‐
tion
accesses
val‐
ues,
the
func‐
tion
accesses
the
``sub‐
script''
of
the
pre‐
vi‐
ous
call.
It
fails
(or
in
the
absence
of
an
oper‐
a‐
tor,
returns
null)
if
there
was
no
valid
sub‐
script
for
the
pre‐
vi‐
ous
call.
The
name
argu‐
ment
should
not
be
quoted.
Since
exact
ta‐
ble
sizes
are
not
defined,
the
inter‐
ro‐
ga‐
tion
oper‐
a‐
tor
should
be
used
to
detect
end-
of-
ta‐
ble;
for
exam‐
ple:
...
...
If
the
inter‐
ro‐
ga‐
tion
oper‐
a‐
tor
is
not
used,
the
result
of
is
null
if
there
are
no
fur‐
ther
ele‐
ments
in
the
ta‐
ble.
Null
is,
how‐
ever,
a
legal
``sub‐
script''.
tests
whether
the
key word
exists
in
the
ta‐
ble
name
and
returns
one
for
true,
zero
for
false.
The
string
argu‐
ment
is
eval‐
u‐
ated
as
a expres‐
sion.
The
func‐
tion
is
handy
for
con‐
vert‐
ing
numeric
strings
to
numeric
inter‐
nal
form.
can
also
be
used
as
a
crude
form
of
indi‐
rec‐
tion,
as
in:
which
incre‐
ments
the
vari‐
able
xyz.
In
addi‐
tion,
pre‐
ceded
by
the
inter‐
ro‐
ga‐
tion
oper‐
a‐
tor
per‐
mits
the
user
to
con‐
trol
error
con‐
di‐
tions.
For
exam‐
ple:
returns
the
value
zero
if
there
is
no
file
named
(instead
of
halt‐
ing
the
user's
pro‐
gram).
The
fol‐
low‐
ing
exe‐
cutes
a
to
the
label
(if
it
exists):
If
the com‐
mand
is
avail‐
able,
the
func‐
tion
pro‐
duces
out‐
put
on
devices
rec‐
og‐
nized
by
The
requests
are
as
fol‐
lows:
Call Func‐
tion
causes
fur‐
ther plot
out‐
put
to
be
piped
into
tplot
with
an
argu‐
ment
of
term
can
be
up
to
40
char‐
ac‐
ters
in
length.
``erases''
the
plot‐
ter.
labels
the
cur‐
rent
point
with string.
draws
the
line
between (x1,y1)
and
(x2,y2).
draws
a
cir‐
cle
with
cen‐
ter (x,y)
and
radius
r.
draws
an
arc
(coun‐
ter‐
clock‐
wise)
with
cen‐
ter (x1,y1)
and
end‐
points
(x2,y2)
and
(x3,y3).
is
not
imple‐
mented.
makes
the
cur‐
rent
point (x,y).
draws
a
line
from
the
cur‐
rent
point
to (x,y).
draws
a
point
at (x,y).
sets
the
line
mode
to string.
makes (x1,y1)
the
lower
left
cor‐
ner
of
the
plot‐
ting
area
and
(x2,y2)
the
upper
right
cor‐
ner
of
the
plot‐
ting
area.
causes
sub‐
se‐
quent
x
(y) coor‐
di‐
nates
to
be
mul‐
ti‐
plied
by
x1
(y1)
and
then
added
to
x2
(y2)
before
they
are
plot‐
ted.
The
ini‐
tial
scal‐
ing
is
Some
requests
do
not
apply
to
all
plot‐
ters.
All
requests
except
zero
and
twelve
are
imple‐
mented
by
pip‐
ing
char‐
ac‐
ters
to
tplot.
Each
state‐
ment
exe‐
cuted
from
the
key‐
board
re-
invokes
mak‐
ing
the
results
unpre‐
dictable
if
a
com‐
plete
pic‐
ture
is
not
done
in
a
sin‐
gle
oper‐
a‐
tion.
Plot‐
ting
should
thus
be
done
either
in
a
func‐
tion
or
a
com‐
plete
pro‐
gram,
so
all
the
out‐
put
can
be
directed
to
in
a
sin‐
gle
stream.
in
imme‐
di‐
ate
mode, returns
the
most
recently
com‐
puted
value.
EXTER‐
NAL
INFLU‐
ENCES
Envi‐
ron‐
ment
Vari‐
ables
deter‐
mines
the
col‐
lat‐
ing
sequence
used
in
eval‐
u‐
at‐
ing
reg‐
u‐
lar
expres‐
sions.
deter‐
mines
the
char‐
ac‐
ters
matched
by
char‐
ac‐
ter
class
expres‐
sions
in
reg‐
u‐
lar
expres‐
sions.
If
or
is
not
spec‐
i‐
fied
in
the
envi‐
ron‐
ment
or
is
set
to
the
empty
string,
the
value
of
is
used
as
a
default
for
each
unspec‐
i‐
fied
or
empty
vari‐
able.
If
is
not
spec‐
i‐
fied
or
is
set
to
the
empty
string,
a
default
of
"C"
(see
lang(5))
is
used
instead
of
If
any
inter‐
na‐
tion‐
al‐
iza‐
tion
vari‐
able
con‐
tains
an
invalid
set‐
ting,
behaves
as
if
all
inter‐
na‐
tion‐
al‐
iza‐
tion
vari‐
ables
are
set
to
"C".
See
env‐
i‐
ron(5).
Inter‐
na‐
tional
Code
Set
Sup‐
port
Sin‐
gle-
byte
char‐
ac‐
ter
code
sets
are
sup‐
ported.
EXAM‐
PLES
Using
as
a
cal‐
cu‐
la‐
tor
is
the
shell
prompt):
$ bs
# Distance (inches) light travels in a nanosecond.
186000 * 5280 * 12 / 1e9
11.78496
...
# Compound interest (6% for 5 years on $1,000).
int = .06 / 4
bal = 1000
for i = 1 5*4 bal = bal + bal*int
bal - 1000
346.855007
...
The
out‐
line
of
a
typ‐
i‐
cal
pro‐
gram:
# initialize things:
var1 = 1
open("read", "infile", "r")
...
# compute:
while ?(str = read)
...
next
# clean up:
close("read")
...
# last statement executed (exit or stop):
exit
# last input line:
run
Input/Out‐
put
exam‐
ples:
# Copy file oldfile to file newfile.
open("read", "oldfile", "r")
open("write", "newfile", "w")
...
while ?(write = read)
...
# close "read" and "write":
close("read")
close("write")
# Pipe between commands.
open("ls", "!ls *", "r")
open("pr", "!pr -2 -h 'List'", "w")
while ?(pr = ls) ...
...
# be sure to close (wait for) these:
close("ls")
close("pr")
WARN‐
INGS
The
graph‐
ics
mode
is
not
par‐
tic‐
u‐
larly
use‐
ful
unless
the
com‐
mand
is
avail‐
able
on
your
sys‐
tem.
is
not
tol‐
er‐
ant
of
some
errors.
For
exam‐
ple,
mistyp‐
ing
a
dec‐
la‐
ra‐
tion
is
dif‐
fi‐
cult
to
cor‐
rect
because
a
new
def‐
i‐
ni‐
tion
can‐
not
be
made
with‐
out
doing
a
The
best
solu‐
tion
in
such
a
case
is
to
start
by
using
the
com‐
mand.
SEE
ALSO
ed(1),
sh(1),
access(2),
printf(3S),
stdio(3S),
lang(5),
reg‐
exp(5).
See
Sec‐
tion
(3M)
for
a
fur‐
ther
descrip‐
tion
of
the
math‐
e‐
mat‐
i‐
cal
func‐
tions.
is
used
for
expo‐
nen‐
ti‐
a‐
tion
—
see
exp(3M));
uses
the
Stan‐
dard
I/O
pack‐
age.
bs(1)