diff --git a/tsshbatch.py b/tsshbatch.py index d5f4371..0009821 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -14,8 +14,8 @@ # Version Information - Overwritten by makefile during release process ##### -GITID = '51f8f43 tundra Fri Oct 14 14:44:40 2016 -0500' -VERSION = '1.316' +GITID = '0c4840a tundra Sat Oct 15 15:29:02 2016 -0500' +VERSION = '1.317' ##### diff --git a/tsshbatch.rst b/tsshbatch.rst index 1ee6174..8193e54 100644 --- a/tsshbatch.rst +++ b/tsshbatch.rst @@ -847,7 +847,7 @@ references. Note, however, that references to builtin variables will fail unless you have overriden them. Why? Because builtins don't get defined until a host connection is attempted. This doesn't happen -until *after* all user defined variable processing and file includes +until *after* all global variable processing and file includes have been done. So:: .define MYINCLUDE = /some/fine/file # OK @@ -862,7 +862,7 @@ .define __HOSTNAME__ ! hostname # Override the builtin .include __HOSTNAME__ # OK -As a matter of keeping things simple, stick to user defined variables +As a matter of keeping things simple, stick to global variables as part of an ``.include`` target. @@ -963,31 +963,36 @@ Types Of Variables ================== -``tsshbatch`` has three different kinds of variables: +``tsshbatch`` has four different kinds of variables: - - *User Defined Variables* are the kind in the example above. + - *Global Variables* are the kind in the example above. You, the user, define them as you wish in a command file or host file. + - *Local Variables* work exactly the same a global variables, except + that they can only be used in the file (command- or host) in which + they are defined. These variables are defined with the ``.local + name = value`` syntax. + - *Execution Variables* run any program or script of your choosing (on the same machine you're running ``tsshbatch``) and assign - the results to a variable. + the results to either a global- or locala variable. - *Builtin Variables* are variables the ``tsshbatch`` itself defines. You can override their default values by creating - a User Defined Variable of the same name. + a Global Variable of the same name. Where And When Do Variables Get Processed? ========================================== -User Defined and Execution Variables are defined in either a +Global, Local, and Execution Variables are defined in either a host file or command file. Builtin Variables are defined within ``tsshbatch`` itself unless you override them. -User Defined Variables are *all* read in and *then* used. If you do +Global Variables are *all* read in and *then* used. If you do something like this:: .define __FOO__ = firstfoo @@ -1001,9 +1006,12 @@ the second definition of __FOO__ has been read in ... and last definition wins. -Execution Variables are like User Defined Variables. They get -processed a single time *at the time they're read in* from a -command file or host file. +Local Variables are read in as a command- or host file is +processed. They can only be referenced *within the same +file* - i.e., They are not visible to any other file. + +Execution Variables are processed a single time *at the time they're +read in* from a command file or host file. Builtin Variables get evaluated *every time ``tsshbatch`` prepares to connect to a new host* (unless you've overriden them). That way, the @@ -1011,10 +1019,10 @@ Keep in mind that ``tsshbatch`` isn't a programming language. It's "variables" are simple string substitutions with "last one wins" -semantics. There is no notion of scope, for example. If you define -the same variable in, say, a command file and also in the -host file, the latter will "win". Why? Because -``hostlistfiles`` are always read in after any ``cmdfiles``. +semantics (for globals). If you define the same global variable in, +say, a command file and also in the host file, the latter will "win". +Why? Because ``hostlistfiles`` are always read in after any +``cmdfiles``. Finally, variable references in a definition are *ignored*. Say you do this in a command file:: @@ -1031,8 +1039,8 @@ you really want to avoid. Trust us on this one. -User-Defined Variables -====================== +Global Variables +================ ``tsshbatch`` allows you to define variables which will then be used to replace matching strings in ``cmdfiles``, ``hostlistfiles``, and @@ -1095,15 +1103,65 @@ or commands passed on the command line. +Local Variables +=============== + +As we saw previously, global variables have "last one wins" +semantics. So, if the same variable name appears in different +files, the last instance read will be the value assigned to +that variable. Sometimes, you don't want this behavior. You +want to define a variable in a file and *only use it there +without changing a global variable with the same name*. + +Say we have three files:: + + # First command file + .define __DEFAULT__ = ls -al # global variable + + # Second command file + .local __DEFAULT__ = ls -1 # variable is local to 2nd file + __DEFAULT__ + + + # Third command file + __DEFAULT__ + + +Now, say we run this command:: + + tsshbatch.py -xH"somehost" -f file1 -f file2 -f file3 + + +The net commands to be run on ``somehost`` will be:: + + ls -1 + ls -al + +The reference to ``__DEFAULT`` in ``file2`` is resolved with the +*local* definition, and the reference in ``file3`` is resolved with +the *global* definition. + +Local variables accompish several things. First, they "insulate" a +host- or command file from prior- or subsequent variable definitions +found in other files. You are guaranteed that the local copy of a +varaible always "wins". + +Conversely, local variables also protect global variables of the same +name from changing. In the example above, we have default behavior +which can be overriden in a case-by-case basis, without changing the +"master" definition. + + Execution Variables =================== -Execution Variables are actually a special case of User Defined + +Execution Variables are actually a special case of Global and Local Variables. That is, they are evaluated at the same time and in the -same manner as any other User Defined Variable. The difference is -that a User Defined Variable describes a *literal string replacement*. -But an Execution Variable *runs a command, program, or script and -assigns the results to the variable*. +same manner as any other variable. The difference is that a normal +variable describes a *literal string replacement*. But an Execution +Variable *runs a command, program, or script and assigns the results +to the variable*. For example, suppose you want create a file on many machines, and you want that file to be named based on who ran the ``tsshbatch`` job. @@ -1117,8 +1175,12 @@ updated) on every machine in the host file or named with ``-H``. +Similarly, you can do the same thing with local variables:: + + .local __TYPE__ = ! uname + Notice it is the ``!`` character that distinguishes an Execution -Variable from a User Defined Variable. It is this character that +Variable from a Global Variable. It is this character that tells ``tsshbatch``, "Go run the command to the right of me and return the results." The trailing space is optional and the definition could be written as:: @@ -1449,7 +1511,7 @@ :: - $Id: '51f8f43 tundra Fri Oct 14 14:44:40 2016 -0500' + $Id: '0c4840a tundra Sat Oct 15 15:29:02 2016 -0500' This document was produced with ``emacs``, ``RestructuredText``, and ``TeX Live``. diff --git a/version b/version index 0f16e51..5372317 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.316 +1.317