Eval Operations#
This page documents all eval operations.
!eval#
Evaluate environment variables in a document
The !eval operation expands the expressions in the strings beneath it. Each is an expr-lang expression evaluated against the evaluation environment (o eval -e name=value). $[expr] is replaced by the expression's value as text; a string that is exactly .[expr] is replaced by the value itself, keeping its type. $USER is not an expression and stays as it is written; .[getenv("USER")] reads the OS environment.
Child: Document whose strings hold $[...] or .[...] expressions
Examples:
- ```tony name: !eval '.[getenv("USER")]'
!exec#
Execute a shell command and capture output
The !exec operation executes a shell command and captures its stdout. The child must be a string containing the command to execute. The command is run with 'sh -c'.
Child: String containing shell command
Examples:
- ```tony date: !exec "date -u +%Y-%m-%d"
!file#
Load content from a file or URL
The !file operation loads content from a local file path or HTTP/HTTPS URL. The child must be a string containing the path or URL. The content is answered as a string, not parsed; !tovalue.file parses it.
Child: String containing file path or URL
Examples:
- ```tony motd: !file "/etc/motd"
!osenv#
Get value from OS environment variable
The !osenv operation retrieves the value of an OS environment variable. The child must be a string containing the environment variable name.
Child: String containing environment variable name
Examples:
- ```tony home: !osenv "HOME"
See also: !eval
!toint#
Convert a value to an integer
The !toint operation converts its child value to an integer. A number converts when it is a whole number an int64 holds (3.0 is 3; 3.5 is refused), true and false are 1 and 0, and a string must hold a base-10 integer.
Child: Number, bool, or string value to convert
Examples:
- ```tony version: !toint "123"