Expression functions Quoting and embedding expressions

Quoted strings

Text inside single quotes (') is not expanded.

Text inside double quotes (") has variables expanded. A double-quoted string is considered one argument.

A backslash character (`) escapes the next character. For example, to use double-quotes in a string: “I had a "great"` time.”.

When a string doesn’t require variable expansion, use single quotes to speed up evaluation.

If you have two quoted strings next to each other with no spaces, they are considered a single argument. In this example…

set foo = "Hello world"
echo '$foo='"$foo"
$foo=Hello world

…the echo command has one argument: '$foo=Hello world'.

Embedding expression language in Hscript

In HScript, text inside backticks is evaluated as an expression. For example:

echo `strlen("$foo")`

Basically, everything inside the backticks is evaluated as a string of expression language. The result of evaluating the expression then replaces the backquoted part of the HScript command, which is then parsed into arguments.

So, if the expression result is a string of words with spaces, the HScript command will see the words as separate arguments, unless they're inside double quotes.

Original commandExpansionHScript command arguments
foo `'bar' + ' ' + 'baz'`
foo bar baz'bar', 'baz'
foo "`'bar' + ' ' + 'baz'`"
foo "bar baz"'bar baz'

The string parser cannot decode nested quotes such as in the following (horribly contrived) example:

echo `system("echo `ls`")`

…however, it is possible to accomplish this with very careful usage of backquotes (and sometimes multiple backquotes in a row) to protect quote symbols from various levels of evaluation:

echo `system('echo \`ls\`')`

Embedding HScript commands in expressions

To call HScript commands in an expression, use the run function.

string objects = run("opls /obj");

Embedding variables and expression language in string parameters

String parameters are treated like an argument to an HScript command. Variables are expanded, and you can use backticks to embed expressions.

This is very useful in parameters that control filenames, where you often include the $F (frame number) variable in the name. Using backquoted expressions lets you use the padzero function to add leading zeros to the frame number:

frame`padzero(5, $F)`.pic

…giving you filenames such as frame00001.pic, frame00002.pic, and so on.

See expressions in filenames for more information.