Lesson 3: Variables
If you have done some programming before you will probably be familiar with the term “variable”. However, this tutorial is intended to teach the concept of variables from the ground up. So here is a definition: “A variable is a language item to store something”. In ScriptFTP that something means just text. Let us look at an example:
The output of the script is the following:
A variable does not need to be declared before use. In other words, you do not need to state explicitly in your script that the word “my_number” is a variable you are going to use. Just use the variable. The only restriction on variable names is that command names are not allowed.
You can use variables for storing the parameters of a command and then call the command using these variables.
Variables may also be used to store the value a command returns:
Just like commands ScriptFTP features a set of operators for calculating arithmetical or logical expressions. In the above example we used the == operator in order to check whether the content of the variable is equal to “OK”. Operators also include +,-,*,/ among others. Have a look at Operators for more information.
As mentioned before every ScriptFTP variable holds a text string and therefore it is necessary to enclose the text with quotes, however, if you supply a number, the quotes may be omitted.
The script output is:
Next Lesson: IF, WHILE and GOTO