Command output redirection

WARNING: XSH2 redirection syntax is not yet finished. It is currently the same as in XSH1 but this may be drastically changed in the future releases.

Output redirection can be used to pipe output of some XSH command to some external program, or to capture it to a variable. Redirection of output of more than one XSH command can be achieved using the do command.

Redirect output to an external program

The syntax for redirecting the output of a XSH command to an external program, is xsh-command | shell-command ;, where xsh-command is any XSH2 command and shell-command is any command (or code) recognized by the default shell interpreter of the operating system (i.e. on UNIX systems by /bin/sh or /bin/csh, on Windows systems by cmd). The shell command may contain further redirections (as supported by the system shell interpreter), but should not contain semicolons, except when the whole shell command is enclosed in brackets.

Example 5. Use well-known UNIX commands to filter XPath-based XML listing from a document and count the results

xsh> ls //something/* | grep foo | wc

Capture output to a variable

The syntax for capturing the output of an XSH command to a variable is xsh-command |> $variable, where xsh-command is any XSH command and $variable is any valid name for a variable.

Example 6. Store the number of all words in a variable named count.

xsh> count //words |> $count