![]() | ![]() | |||||||||||||||
|
Command Argument ShortcutsCommand line arguments are additional data passed to a script on the command that executes the script. These may include things like filenames and option switches. Although there is a built-in package to handle arguments (command_line), for compatibility, the familiar Bourne shell syntax can also be used:
For example, => myscript a b c $1 is "a", $2 is "b" and $3 is "c". The argument variables are always string. The number of parameters, $#, will be 3. Attempting to access an argument that doesn't exist, such as $4 in this example, is an error. Redirection operators are not arguments because they are processed prior to running the command. If you run script as an argument to the spar command, any arguments occurring after the script name will be treated as the arguments to the script. For example, $ spar --trace myscript a b c In this example, $1 is still "a". The "--trace" argument is not visible to your script. Here is a longer script example. -- a short-cut for ls -l for one optional parameter
Example: Using Bourne Shell arguments
If there are more than 9 arguments, they can be accessed with the command_line package. The Bourne shell form are intended as command line shortcuts and the command_line package should normally be used in a well-structured script. SparForte also permits these command line tokens in dollar expansions. Here is an example of removing a traditional shell temporary file. rm "/tmp/temp."$$
Example: Using Bourne Shell arguments - another example
The status code of the last command executed is returned from a script when it finishes executing. Traditionally, a non-zero status is an error condition. A SparForte script can set its status code using the command_line package. Bourne Shell: $@, $# and shift are not available. Use the command_line package for these and loop through the parameters. |
![]() Block Statements and Subprograms |
![]() |
![]() |