Continuing Education on New Data Standards & Technologies

Search thousands of Continuing Education resources for metadata professionals

Advanced Search

xmlsh - XML Shell: Core Syntax

Go to the resource directly at

Linked Data



Dublin Core


xmlsh - XML Shell: Core Syntax


A simple-command is a sequence of non-blank words separated by blanks. The first word specifies the name of the command to be executed. Except as specified below, the remaining words are passed as arguments to the invoked command.

The command name is used to locate the command (builtin, nternal,external) .

A pipeline is a sequence of one or more commands separated by |. The standard output of each command but the last is connected by a Pipe to the standard input of the next command. Each command is run as a separate thread (if builtin or internal) or as a separate process (if external). The shell waits for the last command to terminate.

The exit status of a pipeline is the exit status of the last command in the pipeline.

A list is a sequence of one or more pipelines separated by ;, &, &&, or ||, and optionally terminated by ; or &. Of these four symbols, ; and & have equal precedence, which is lower than that of && and ||. The symbols && and || also have equal precedence.

A semicolon (;) causes sequential execution of the preceding pipeline, that is, the shell waits for the pipeline to finish before executing any commands following the semicolon. An ampersand (&) causes asynchronous execution of the preceding pipeline, that is, the shell does not wait for that pipeline to finish.

The symbol && (||) causes the list following it to be executed only if the preceding pipeline returns a zero (non-zero) status.

An arbitrary number of newlines may appear in a list, instead of semicolons, to delimit commands.

A command is either a simple-command or one of the following.

Unless otherwise stated, the value returned by a command is that of the last simple-command executed in the command.

for name [ in word ... ] ; do list done

if list ; then list ; [ elif list ; then list ; ] ... [ else list ; ] fi

while list ; do list ; done

A while command repeatedly executes the while list and, if the exit status of the last command in the list is zero, executes the do list; otherwise the loop terminates. If no commands in the do list are executed, then the while command returns a zero exit status; until may be used in place of while to negate the loop termination test.

until list ; do list ; done

Until command is the same as a while command except that the loop terminates when the check evaluates to true instead of false.

The list following if is executed and, if it returns a zero exit status, the list following the first then is executed. Otherwise, the list following elif is executed and, if its value is zero, the list following the next then is executed. Failing that, the else list is executed. If no else list or then list is executed, then the if command returns a zero exit status.

The following words are only recognized as the first word of a command and when not quoted:

if then else elif fi case esac for while until do eval done try catch finally throw { }

A word beginning with # causes that word and all the following characters up to a newline to be ignored.

Words are scanned for $ which indicates variable substition.

$name or ${name} is substituted for the value of the variable named "name".

$0 $2 ... $nnnnn is substituted for the positional paramter (note this differs from sh where n may be > 9)

There are several builtin variables

$? the exit code of the last command

$@ All positional parameters as if they were quoted. equal to "$1" "$2" "$3"

$$ The thread id of the current shell

$! The thread id of the last background command executed with "cmd &"

$* All positional parameters unquoted. equal to $1 $2 $3 ...

$# The number of positional paramters

$(cmd) cmd is executed and its output is is substituted with newlines turned into word seperators

`cmd` Same as $(cmd)

$<(cmd) cmd is executed and the output parsed as an XML document and the result is an XML expression

Single and double quotes are implemented similar to sh/bash/ksh. Text in single quotes ('text') is treated literally with no expansion and treated as one word. Text in double quotes ( "text") is variable expanded then treated as one word. Within double quotes the escape character backslash (\) can be used to remove special meaning from $ or double quotes (").

<{{ }}> are block quotes. These are treated as single quotes but are useful to quote large text with unknown content. No expansion or interpretation of the contents, and the result is treated as one word with the <{{ and }}> removed.

The shell reads commands from the string between $( and ) and the standard output from these commands may

be used as all or part of a word. Trailing newlines from the standard output are removed.

No interpretation is done on the string before the string is read, except to remove backslashes (\) used to escape other


Sets the value of variable "a" to "This is Text

Legacy "backtick" syntax is also supported.

Note that the $( cmd ) syntax can nest but the `cmd` cannot nest.

If the command is of the form $(<file) then the file is read, trailing newlines stripped and the result is a string containing the entire file.

Variable expansion is done on "file" so that the following syntax works:

Similar to Command Substitution, $<( command ) indicates a command which is executed and the output is parsed as an XML document.

Command is executed identically to the $(command) syntax except that the result is then parsed as an XML document and the result is an XML expression.

If the command is of the form $<(<file) then the file is read and parsed as an XML document. The resulting expression is of XML type.

Variable expansion is done on "file" so that the following syntax works:

Commands can be either builtin, internal, user defined or external commands.

Builtin commands are "special" in that they interact with the shell environment.

Internal commands implemented as a "convenience" in that they could be also implemented as

user defined commands. User defined commands are supported by creation of a jar containing

classes which implement the ICommand interface. External commands are any command (process)

outside of xmlsh. External commands are executed as seperate processes, all other commands are

executed with the JVM of xmlsh.

The core syntax for xmlsh was derived from the open source Shell Command Language syntax document. xmlsh does not follow this syntax exactly, but rather it was used as a basis.This is a synopsis of the supported syntax.example:producesUser defined functions can be invoked with either the command or the function call syntax.Builtin functions and module defined functions may only be called with the function call syntaxThis is an *expression* and may be used anywhere a word may be used, including variable assignment.Arguments are evaluated exactly like command arguments (blankspace seperated , not comma ","). Variable expansion and wildcard expansion occur in the argument list exactly like command invocaton. The resulting arguments are passed to the function, and the return value is substituted.See Function Syntax for detailsSee Also BasicSyntax


Copyright to metadata belongs to Continuing Education Metadata Project.


text/html; charset=us-ascii 21.96 KB




Hyperlink Item Type Metadata



Xmlsh staff, “xmlsh - XML Shell: Core Syntax,” Continuing Education on New Data Standards & Technologies, accessed March 4, 2021,