bs(1)

bs(1)

possible to know whether a is a number or a string when the format call is coded, coercing a to the type required by f by either adding zero (for e or f format) or concatenating (_) the null string (for s format) should be considered.

index(x, y)

returns the number of the ®rst position in x that any of the characters from y matches. No match yields zero.

trans(s, f, t)

Translates characters of the source s from matching characters in f to a character in the same position in t. Source characters that do not appear in f are copied to the result. If the string f is longer than t, source characters that match in the excess portion of f do not appear in the result.

substr(s, start, width)

returns the sub-string of s de®ned by the starting position and width.

match(string, pattern)

mstring(n) The pattern is a regular expression according to the Basic Regular Expression de®nition (see regexp(5)). mstring returns the n-th (1 <= n <= 10) substring of the subject that occurred between pairs of the pattern symbols \( and \) for the most recent call to match. To succeed, patterns must match the beginning of the string (as if all patterns began with Ã). The function returns the number of characters matched. For example:

match("a123ab123", ".*\([a-z]\)") == 6 mstring(1) == "b"

File handling

open(name, file, function) close(name)

name argument must be a bs variable name (passed as a string). For the open, the ®le argument can be:

1.a 0 (zero), 1, or 2 representing standard input, output, or error output, respec- tively;

2.a string representing a ®le name; or

3.a string beginning with an ! representing a command to be executed (via sh -c). The function argument must be either r (read), w (write), W (write without new-line), or a (append). After a close, name reverts to being an ordi- nary variable. If name was a pipe, a wait() is executed before the close com- pletes (see wait(2)). The bs exit command does not do such a wait. The ini- tial associations are:

open("get", 0, "r") open("put", 1, "w") open("puterr", 2, "w")

Examples are given in the following section.

access(s, m)

executes access() (see access(2)).

ftype(s) returns a single character ®le type indication: f for regular ®le, p for FIFO (i.e., named pipe), d for directory, b for block special, or c for character special.

Tables

table(name, size)

A table in bs is an associatively accessed, single-dimension array. ``Subscripts'' (called keys) are strings (numbers are converted). The name argument must be a bs variable name (passed as a string). The size argument sets the minimum number of elements to be allocated. bs prints an error message and stops on table over¯ow. The result of table is name.

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

HP-UX Release 11i: December 2000

− 5 −

Section 153

b