Revision [422]

This is an old revision of CommandRedirect made by DavidLee on 2009-03-01 04:41:53.

 

IO Redirection


IO can be redirected as per the unix shells (sh) with "> file" , ">>file" "< file" , "2> file".
Also Here Documents are supported for both text and XML documents.


Input Redirection

Using the syntax
command < file

Input for command is taken from the file "file" (either byte stream or Xml document).

Output Redirection

Using the syntax
command > file

Output for command is passed to file "file" (either byte stream or Xml document).



Stderr Redirection

Using the syntax
command 2> file

Stderr Output for command is passed to file "file" (either byte stream or Xml document).


Here Documents

As per the unix shells, "Here Documents" are supported.
A "here Document" is data embedded directly in the script or from the terminal which becomes the standard input of a command.
The syntax is:

	command <<EOF
Some Text
Here until the magic  "EOF" is found 
on a line by its own
EOF

The tag "EOF" can be any string. Here documents work as well for text as xml documents.
For example:

xread doc <<EOF
<foo>
	bar
 </foo>
EOF

URL Input

URL's can be used for input redirection any place a file is used.
For example

$ xcat < http://test.xmlsh.org/data/books.xml


Also any Internal or Builtin commands that take filenames will take URL's for input files.
For example the above can be rewritten without using redirection

$ xcat  http://test.xmlsh.org/data/books.xml


In both cases, the Base URI of the resulting document is preserved.

Note that URL redirection can only be used for input, not for output at this time.



Ports

A variable can be used for input or output redirection. This is called a "Port".
the syntax is {variable} wherever a file would be used.

Example the following two commands are equivilent

$ xls >{doc}
$ xls | xread doc


And so are the following
$ xcat <{doc}
$ echo $doc | xcat


Ports can be Appended. This will turn a non-sequenced variable into a sequenced variable.
The one exception is that if the variable is initially empty, or contains a single atomic value,
AND the output of the command is text then the appending works like appending to a file,
that is the strings are concatenated.

Example

$ xls >{doc}
$ xls >>{doc}


Now $doc is a sequence of 2 documents. The following would produce equivilent results

$ xls | xread doc
$ doc=<[$doc,$doc]>


Text concatenation works when text mode commands are used.

$ echo foo >{port}
$ echo bar >>{port}
$ echo $port
foobar



See Also BasicSyntax


There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki