Charles.Forsyth20060303-partialeea662d19 years agoHistory
186 lines · 3.0 KB · Text
RawDownload
.TH SH-STRING 1.SH NAMEprefix, in, splitl, splitr, drop, take, splitstrl, splitstrr, tolower, toupper, len, alen, slice \- shell script string manipulation.SH SYNOPSIS.B load string .B prefix.I pre s.br.B in.I c cl.br.B ${splitl.IB "s cl" }.br.B ${splitr.IB "s cl" }.br.B ${splitstrl.IB "s t" }.br.B ${splitstrr.IB "s t" }.br.B ${take.IB "s cl" }.br.B ${tolower.IB s }.br.B ${toupper.IB s }.br.B ${len.IB s }.br.B ${alen.IB s }.br.B ${slice.IB "start end s" }.br.B ${fields.IB "cl s" }.br.B ${padl.I n[.IR s ....RB ] }.br.B ${padr.I n[.IR s ....RB ] }.br.SH DESCRIPTION.I Stringis a loadable module for.IR sh (1)that provides a shell-script interface to the stringmanipulation commands found in.IR string (2),with a couple of other facilities thrown in for goodmeasure. Each of the substitution builtins.BR splitl ,.BR splitr ,.BR drop ,.BR take ,.BR splitstrl ,.BR splitstrr ,.BR tolower ,and.BR toupperimplements the same functionality as that provided bythe function of the same name in.IR string (2).Where a function in the.IR string (2)module returns a tuple, the equivalent builtin yieldsa two-element list; the others yield a list with a singleelement..PPIn all.I stringcommands, the number of arguments provided mustbe exactly that required by the command so, for instance,giving an undefined variable (a zero element list) asan argument will cause a.B usageexception to be generated..PPThe two builtins.B prefixand.B inare again similar to their.IR string (2)counterparts - their return value is true (an empty string)if the equivalent.IR string (2)function would be non-zero..PP.B Lenreturns the length of its argument.IR s ..B Alenreturns the length of its argument.IR swhen converted to a byte-array. (This will bedifferent from the result of.B lenwhen.I scontains non-ASCII characters)..B Sliceis similar to the string-slicing operator in Limbo;it returns the section of.I sstarting at index.I startand ending just before index.IR end ..I Endmay be the literal string.BR end ,in which.BI "${slice " start " end}"is the same as.BI "${slice " start " ${len " s "}}"\fR.\fPUnlike in Limbo, nothing untoward happens ifan out-of-range slice is taken: any out ofrange indices are trimmed to within the boundsof.IR s ..PP.B Fieldsis similar to.B ${split}in.IR sh (1),but does not merge field separator characters.It splits.I sinto fields separated by characters in class.IR cl ;if there are.I ncharacters matching.I clinside.IR s ,.B fieldswill yield.IR n +1items in its result..PP.B Padland.B padrwiden the string.I sto.I ncharacters, padding it with spaces on theright (for .BR padl )or the left (for.BR padr )as necessary.If.I sis already at least.I ncharacters wide, it is left unchanged.If several arguments are given, theyare concatenated, separated with spaces, beforepadding takes place..SH SOURCE.B /appl/cmd/sh/string.b.SH SEE ALSO.IR string (2),.IR sh (1),.IR sh-std (1),.IR sh-expr (1)