|Purpose:||Save a copy of the current disk drive, directory, environment, alias and function lists, and special characters|
|GLOBALLISTS||Global aliases / user variable functions|
See also: ENDLOCAL.
SETLOCAL can be used on the command line, in aliases, in library functions, and in batch files.
SETLOCAL will save :
•the default disk drive and directory
•the alias list
•the user-defined function list
•The directory stack (PUSHD)
•the special character set (command separator, escape character, parameter character, decimal separator, and thousands separator)
•the SETDOS /X setting
•the SETDOS /F setting
After using SETLOCAL, you can change the values of any or all of the above, and later restore the original values with an ENDLOCAL command, or just by exiting the batch file.
SETLOCAL does not save the command history or array variables.
If you have global aliases and/or functions, SETLOCAL will now copy them to a local list for the duration of the SETLOCAL. The matching ENDLOCAL will reset them to the global list. If you have both local and global aliases or functions defined, SETLOCAL will only save the local list (which will be restored by ENDLOCAL).
SETLOCAL supports the EnableExtensions, DisableExtensions, EnableDelayedExpansion, and DisableDelayedExpansion arguments from CMD. (Though they're not necessary, since TCC either sets those by default or through the OPTION command.)
For example, this batch file fragment saves everything, removes all aliases so that aliases will not affect batch file commands, changes the disk and directory, changes the command separator, runs a program, and then restores the original values:
program ~ echo Done!
SETLOCAL and ENDLOCAL may be nested up to 32 levels deep in each batch file. You can also have multiple SETLOCAL / ENDLOCAL pairs within a batch file, and nested batch files can each have their own SETLOCAL / ENDLOCAL pairs.
SETLOCAL does not override the Local Aliases configuration option. Consequently changing aliases inside a SETLOCAL / ENDLOCAL pair affects the definition of aliases of other concurrently executing sessions of TCC.
You can also use SETLOCAL and ENDLOCAL in an alias or at the command line. The maximum nesting level from a command line or alias is 32 levels. Unlike batch files, you are responsible for matching the SETLOCAL / ENDLOCAL calls from an alias or command line; TCC will not perform an automatic ENDLOCAL.
An ENDLOCAL is performed automatically at the end of a batch file, or when returning from a "GOSUB filename". If you invoke one batch file from another without using CALL, the first batch file is terminated, and an automatic ENDLOCAL is performed; the second batch file inherits the settings as they were prior to any SETLOCAL.
You can "export" modified variables from inside a SETLOCAL / ENDLOCAL block. See ENDLOCAL for details.
|GLOBALLISTS||Prevent SETLOCAL from switching to local alias and user-defined variable function lists during the SETLOCAL duration.|