Documentation

Variables

Variable exampleLike in traditional programming languages, Variables are containers that hold a value.  Variable types include: 64-bit integers, Double-precision floating point, strings with other embedded variables and functions, literal strings, string lists (arrays), tables (associative arrays), JSON objects, and COM object references.  Variables can be persistent across sessions or can be Local to a specific script for high performance.

For example, just typing:

a = 123

will assign the number 123 to the variable named "a".

To access the value of a variable, precede its name with the @ character. Note that this is different than in PHP or TINTIN where variables start with a $ character. (TeSSH uses the $ character for local variables). For example:

#SHOW @a

You can also use the #VARIABLE command to assign a variable:

#VAR a 123

This is an older syntax, but it supports several advanced features such as Indirect variable assignment.

Expressions and functions can be used within the variable assignment. For example:

b = @a+1

would assign the number 124 to the @b variable. To force an expression to be evaluated, you can enclose the expression in () parenthesis. To assign a literal string value, enclose the string in " quotes. To perform variable expansion but *not* expression evaluation, enclose the value in {} braces. Here are several examples:

b = @a+1 // 124 assigned to @b
b = (@a+1) // same as above
b = "@a+1" // assigns the literal string "@a+1" to @b
b = {@a+1} // assigns the string "123+1" to @b

In the first two cases, the @b variable is set to Auto-typed. In the 3rd line using " the @b variable is set to a "literal string" type. In the 4th line using the {} the @b variable is set to a "string (expanded)" type to show that variable expansion is allowed.

In general, be sure to put " quotes around literal strings. If you want a string value that allows variable expansion, use {} instead of " quotes. This is similar to PHP in which variable expansion is allowed within " quotes but not within ' single quotes. TeSSH " quotes are like the PHP ' single quotes. TeSSH {} braces are like the PHP " double quotes.

Add comment

Login or register to post comments