Revision [428]
This is an old revision of Variables made by DavidLee on 2009-03-11 05:43:05.
Variables
xmlsh variables can be either strings or XML types (infoset, including sequences).There is no limit to the size of variables besides JVM memory.
Variables are created using variable assignment (Variables). The type of the expression determins
if a variable is a string or XML variable. Variables can be re-assigned and this can change their type.
Example of string assignments
A=string A="string" A='string' B="another $A" C=${B} D=$(echo yet more strings) E=$(ls)
Example of XML assignments
A=<[<foo/>]> A=<[1,2,3,<foo>bar</foo>]> A=$<(xls) DOC=<[<foo><bar>text</bar></foo>]> T=<[<spam>{$DOC//bar}</spam>]>
Sequence Construction
Variable assignment supports a simplified sequence expression, similar to bash and ksh array assignment.var=(elem elem ...)
For example
$ var=(foo bar spam)
Assigns an XML sequence of strings equivilent to
$ var=<[("foo","bar","spam")]>
The values inside () are expanded using Word expansion and Globbing before being assigned.
Note that this is different then non-sequence construction which doesnt do globbing (wildcard expansion).
Assuming there are 21 xml files in the current directory
$ var=(*.xml) $ echo <[ count($var) ]> 21 $ var=*.xml $ echo <[ count($var) ]> 1
Assigns var to be the sequence containing all xml files in the current directory.
The empty sequence construct creates an empty sequence. This is different then string assignment which creates a empty string.
$ var=() $ echo <[count($var)]> 0 $ var="" $ echo <[count($var)]> 1
See Also BasicSyntax