Documentation

Introduction to Variables

Variables are very similar to aliases. The important difference between aliases and variables is that aliases are only expanded when at the beginning of a command, while variables are expanded anywhere. To expand the variable, you precede its name with the @ character. Note that this is different then programming languages like PHP and Perl where variables start with a $.

To define a variable, you use the #VARIABLE command. For example, #VAR path "/home/zugg" stores the string "/home/zugg" into the variable path. To return the contents of the variable, precede its name with the @ character. For example, cd @path would expand to cd /home/zugg.

Another assignment syntax is also provided. As with some programming languages, you can use the syntax variable=value to assign a value to a variable.

To illustrate the use of variables, with the variable @path defined as shown above, you can now create an alias

#ALIAS cdd {cd @path}

Now when you enter cdd on the command line, the current value of the path variable is expanded and the command cd /home/zugg  is sent to the server.

Variables are expanded in the command line too. If you enter cd @path on the command line, it would send cd /home/zugg to the server.

You can edit your variables like this on the command line, or you can use the Package Editor Variables screen.  If you changed the variable by typing this on the command line:

path = "/home/root"

then when you use the cdd alias, it would send cd /home/root to the server.

Variable Types

TeSSH supports several different types of variables.  By default, a variable has the "Auto" type, which means TeSSH will treat it as whatever type is needed by the context of it's use.

To assign a literal string value to a variable, enclose the value in " quotes.  To assign a string but allow variable and function expansion in the value, enclose the value in {} braces.  To evaluate an expression, enclose the expression in ().  Or, since an expression is the default assignment mode, the () are actually optional.  Here are some examples:

a = 123
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

Local Variables

Local variables always start with a $ character instead of a @. A Local variable is temporary and only exists during the execution of the script. However, local variables are much faster than using normal variables. You only use local variables within a script, not from the command line. See the Local Variables topic for more information on this advanced topic.

System Variables

TeSSH has some pre-defined variables that are maintained automatically by the system. These pre-defined variables start with a % character instead of @. They are very similar to functions (which also start with %) except that the system variables do not take any arguments and never have parenthesis after them. For example, the %char system-variable contains your character name (as entered in the Edit Session screen for your session icon). This is very different than the %char function which returns an ascii character value.

String Lists (arrays)

A variable that contains a list of values is called an array, or "string list" in TeSSH.  The syntax for creating a string list looks like this:

list = {item1|this is item2|item 3}

The | character is used to separate each item in the array.  Quotes around each item are optional.  To include a | character in your item, escape it with the ~ character.

Items in the string list are indexed starting at one.  To retreive the nth item in a list, use the syntax @list.n.  For example:

#SHOW @list.2

would display "this is item2" on the screen.  Several functions and commands manipulate string lists, such as #ADDITEM, %additem, %item, etc.

Database Variables (tables)

A string list or array is accessed via a numeric index (starting at 1).  A Database Variable or "table" is accessed via a string "key".  The syntax for creating a table looks like this:

table = {name=Zugg|path=/home/zugg|su=0}

This would create a table with three items.  Each item can be accessed using it's key with the syntax @table.key.  For example:

#SHOW @table.path

would display "/home/zugg" on the screen.  Several functions and commands manipulate tables, such as #ADDKEY, %addkey, %db, etc.

Add comment

Login or register to post comments