Variables

 In HScript, you can assign strings to variables with the set command:

Set a variable

set x = "hello"

Set a global variable

set -g x = "hello"

or

setenv x = "hello"

Unset a variable

set -u x

A variable name must begin with letter or an underscore (_), followed by any number of letters, numbers or underscores.

To use a variable in a command, prefix its name with a dollar sign ($):

> set foo = "bar"
> echo $foo
bar

You can optionally enclose the name of the variable in curly braces ({}) to prevent the variable name from running into surrounding text:

> echo ${foo}baz
barbaz

In addition, when you use curly braces HScript will expand variable references in the name before looking up its value. This lets you simulate simplistic arrays:

set foo1 = Padma
set foo2 = Mohammed
for i = 1 to 2 echo ${foo$i} end
Padma
Mohammed

In HScript, variables can be local or global (sometimes called system variables).

Local variables are local to the script being run. When the script is finished, the variable disappears. Local variables cannot be used outside the script in which they're defined. To create or set a local variable, use set. The variables created by the for and foreach loops are always local.

Global variables are available to all scripts and to any programs started by Houdini. To create or set a global variable, use setenv or set -g.

Variable modifiers

You can add modifiers to the end of variable names to edit the returned value. These modifiers do not change the value stored in the variable, they only change the value returned by the variable reference with the modifier.

To modify the variable value, add :code to the end of the variable name. For example:

> set afile = /home/matt/bin/foo.bar
> echo $afile:e
bar
> echo ${afile}:e
bar

The available codes are:

:h

(Head) The path part of a pathname (that is, the path up to the filename).

> echo ${afile}:h
/home/matt/bin

:t

(Tail) Just the filname part of a pathname.

> echo ${afile}:t
foo.bar

:e

The extension on the end of the filename.

> echo ${afile}:e
bar

:r

(Root) All parts of a pathname except the extension.

> echo ${afile}:r
/home/matt/bin/foo

:s/ptrn/repl/

Substitute occurances of pattern ptrn with repl.

> echo ${afile}:s/foo/baz/
/home/matt/bin/baz.bar

:u

Convert the value to uppercase.

> set str = Hello There
> echo ${str}:u
HELLO THERE

:l

Convert the value to lowercase.

> set str = Hello There
> echo ${str}:l
hello there