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 contains 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 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.
Fields is similar to ${split} in sh(1), but does not merge field separator characters. It splits s into fields separated by characters in class cl; if there are n characters matching cl inside s, fields will yield n+1 items in its result.
Padl and padr widen the string s to n characters, padding it with spaces on the right (for padl) or the left (for padr) as necessary. If s is already at least n characters wide, it is left unchanged. If several arguments are given, they are concatenated, separated with spaces, before padding takes place.
SH-STRING(1 ) | Rev: Tue Mar 31 02:42:38 GMT 2015 |