Defining and using variables |
Variables may be defined in SSCL at the command line or in a valid SSCL script file. Once a variable is defined it is then accessible within the SSCL script for use in other commands.
Defining variables at the command line
Variables may be defined at the command line using the following syntax:
-<variablename> <value>
Example
java -jar sshfactory.jar -f scriptfile.txt -filter '*.txt'
In the above example a variable named filter is defined with a value of '*.txt'.
Note
In the above example the value is quoted with single quotes. This is to prevent your operating system shell from performing command line expansion of the regular expression *.txt. Failure to surround regular expressions with single quotes will result in undesired effects.
Defining variables in scripts
You may define variables in scripts using the set command.
Referencing variables in scripts
Variables defined at the command line or in scripts may be referenced using the following syntax:
${<variablename>}
Example
java -jar sshfactory.jar -f scriptfile.txt -filter '*.txt'
Example script using command line variable
/** * This example demonstrates connecting to a server, performing a directory * listing and then disconnecting. */
set hostname "ssh.myserver.com" set secure true set username "jsmith" set password "secret" connect
// perform directory listing using filter supplied at command line send "ls -al ${filter}"
disconnect |