set
ARES System Manual: exec Shell

(input) @set <variable> <string>
(input) @set <variable> %key
(input) @set <variable> %keys <JSON>
(input) @set <variable> %undefined
(input) @set <variable> %count lines|chars|words|keys in <string>
(input) @set <variable> %line|%char|%word <index> in <string>
(input) @set <variable> %index <key> of <JSON>
(input) @set <variable> = <expression>

Sets a shell environment variable to the specified value. Variable names should start with letters. They are case-sensitive. They may contain underscores, hyphens, and numbers.

The special value %key can be used to set a variable to a new randomly-generated UUID.

The value %undefined can be used to remove a variable.

The %count syntax counts the number of lines, characters, or words in a string, or keys in a JSON object. For example, set n %count chars in ARES sets the environment variable n to 4.

The %line, %char, and %word syntaxes extract individual parts from a string. For example, set w %word 3 in One, Two, Three, Four! sets w to Four! (Indexes start at 0.)

The %keys syntax (not to be confused with %key) will return a space-separated list of keys in the JSON object <JSON>, which can then be iterated over with %word and %count words.

The %index syntax will extract part of a JSON object. It supports . notation for nested objects (but not JSON arrays). For example, set fruit %index alpha in {"alpha":"apple","beta":"banana"} will yield 'apple'.

To use an environment variable, type $ and the variable name. For example, @set x = $x + 1 will modify the variable x by adding 1 to its current value.

To remove variables you no longer need, use set <name> %undefined. It is good practice to clean up after yourself at the end of a script that uses temporary environment variables.

To assign a blank value to a variable, try set <name> "" or set <name> %empty. if also understands these symbols.

Variable substitutions may be used in any exec invocation, i.e. commands that can be called with @ from input.

Environment variables are stored in the env section of the database and can be reviewed with @db show env.

Environment variables may be set to the output from running a system command by using the bundled program xset.

Shell built-in command: This command is part of the exec shell and does not have a corresponding system binary. It must be used shell scripts without a preceding @ and cannot be called directly with the system invoke() API.

To use this command with invoke(), use the syntax exec set <variable> <value> or manipulate the env database section directly with setdbl("env", [<variable>], <value>).