SH-STRING(1) SH-STRING(1) NAME prefix, in, splitl, splitr, drop, take, splitstrl, splitstrr, tolower, toupper, len, alen, slice - shell script string manipulation SYNOPSIS load string prefix pre s in c cl ${splitl s cl} ${splitr s cl} ${splitstrl s t} ${splitstrr s t} ${take s cl} ${tolower s} ${toupper s} ${len s} ${alen s} ${slice start end s} DESCRIPTION String is a loadable module for sh(1) that provides a shell-script interface to the string manipulation commands found in string(2), with a couple of other facilities thrown in for good measure. Each of the substitution builtins splitl, splitr, drop, take, splitstrl, splitstrr, tolower, and toupper implements the same functionality as that pro- vided by the function of the same name in string(2). Where a function in the string(2) module returns a tuple, the equiv- alent builtin yields a two-element list; the others yield a list with a single element. In all string commands, the number of arguments provided must be exactly that required by the command so, for instance, giving an undefined variable (a zero element list) as an argument will cause a usage exception to be generated. The two builtins prefix and in are again similar to their string(2) counterparts - their return value is true (an empty string) if the equivalent string(2) function would be non-zero. Len returns the length of its argument s. Alen returns the length of its argument s when converted to a byte-array. (This will be different from the result of len when s con- tains non-ASCII characters). Slice is similar to the string-slicing operator in Limbo; it returns the section of s starting at index start and ending just before index end. End may be the literal string end, in which ${slice start Page 1 Plan 9 (printed 11/17/24) SH-STRING(1) SH-STRING(1) end} is the same as ${slice start ${len s}}. Unlike in Limbo, nothing untoward happens if an out-of-range slice is taken: any out of range indices are trimmed to within the bounds of s. SOURCE /appl/cmd/sh/string.b SEE ALSO string(2), sh(1), sh-std(1), sh-expr(1) Page 2 Plan 9 (printed 11/17/24)