Product SiteDocumentation Site

7.4.56. SETLOCAL (Linux only)


>>-SETLOCAL()--------------------------------------------------><

Saves the current working directory and the current values of the environment variables that are local to the current process.
For example, SETLOCAL can be used to save the current environment before changing selected settings with the VALUE function (see Section 7.4.71, “VALUE”). To restore the directory and environment, use the ENDLOCAL function (see Section 7.4.29, “ENDLOCAL (Linux only)”.
SETLOCAL returns a value of 1 if the initial directory and environment are successfully saved and a value of 0 if unsuccessful. If SETLOCAL is not followed by an ENDLOCAL function in a procedure, the initial environment saved by SETLOCAL is restored upon exiting the procedure.
Here is an example:

Example 7.70. Builtin function SETLOCAL

/* Current path is "user/bin" */
n = SETLOCAL()           /* saves all environment settings */
/* Now use the VALUE function to change the PATH variable */
p = VALUE("Path","home/user/bin"."ENVIRONMENT")
/* Programs in directory home/user/bin can now be run */
n = ENDLOCAL()           /* restores initial environment including */
                         /* the changed PATH variable, which is    */
                         /* "user/bin"                             */