HP-UX Reference (11i v2 07/12) - 1 User Commands A-M (vol 1)

b
bs(1) bs(1)
item(name, i)
key()
The item function accesses table elements sequentially (in normal use, there is no orderly
progression of key values). Where the item function accesses values, the
key function
accesses the ‘‘subscript’’ of the previous
item call. It fails (or in the absence of an
interrogate operator, returns null) if there was no valid subscript for the previous
item call. The name argument should not be quoted. Since exact table sizes are not
defined, the interrogation operator should be used to detect end-of-table; for example:
table("t", 100)
...
# If word contains "party", the following expression adds one
# to the count of that word:
++t[word]
...
# To print out the the key/value pairs:
for i = 0, ?(s = item(t, i)), ++i if key() put = key()_":"_s
If the interrogation operator is not used, the result of
item is null if there are no further
elements in the table. Null is, however, a legal ‘‘subscript’’.
iskey(name, word)
iskey
tests whether the key word exists in the table name and returns one for true, zero
for false.
Odds and Ends
eval(s) The string argument is evaluated as a bs expression. The function is handy for converting
numeric strings to numeric internal form. eval can also be used as a crude form of
indirection, as in:
name = "xyz" eval("++"_ name)
which increments the variable xyz. In addition, eval preceded by the interrogation
operator permits the user to control bs error conditions. For example:
?eval("open(\"X\", \"XXX\", \"r\")")
returns the value zero if there is no file named XXX (instead of halting the user’s program).
The following executes a goto to the label L (if it exists):
label="L"
if !(?eval("goto "_ label)) puterr = "no label"
plot(
request, args)
If the tplot command is available, the plot function produces output on devices recog-
nized by tplot. The requests are as follows:
Call Function
plot(0, term) causes further plot output to be piped into tplot
with an argument of -Tterm. term can be up to
40 characters in length.
plot(1) ‘‘erases’’ the plotter.
plot(2, string) labels the current point with string.
plot(3, x1, y1, x2, y2) draws the line between (x1,y1) and (x2,y2).
plot(4, x, y, r) draws a circle with center (x,y) and radius r.
plot(5, x1, y1, x2, y2, x3, y3) draws an arc (counterclockwise) with center
(x1,y1) and endpoints (x2,y2) and (x3,y3).
plot(6) is not implemented.
plot(7, x, y) makes the current point (x,y).
plot(8, x, y) draws a line from the current point to (x,y).
plot(9, x, y) draws a point at (x,y).
HP-UX 11i Version 2: December 2007 Update 6 Hewlett-Packard Company 85