HP-UX Reference (11i v2 03/08) - 1 User Commands A-M (vol 1)
b
bs(1) bs(1)
always 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 first 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 defined by the start ing position and width.
match(string, pattern )
mstring(n) The pattern is a regular expression according to the Basic Regular Expression definition
(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 file
argument can be:
1. a 0 (zero), 1, or 2 representing standard input, output, or error output, respec-
tively;
2. a string representing a file 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
ordinary variable. If name was a pipe, a wait() is executed before the close
completes (see wait(2)). The bs exit command does not do such a wait. The
initial 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 file type indication: f for regular file, 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 overflow. The result of
table is name.
item(name, i)
key() The item function accesses table elements sequentially (in normal use, there is no ord-
erly 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 previ-
ous item call. The name argument should not be quoted. Since exact table sizes are
HP-UX 11i Version 2: August 2003 − 5 − Hewlett-Packard Company Section 1−−53