setlocal ENABLEEXTENSIONS / ENABLEDELAYEDEX

Submitted by Extreme on Fri, 01/19/2007 - 01:00.Shell Scripting

Another title might be: "dereferencing with CMD"

setlocal ENABLEEXTENSIONS / ENABLEDELAYEDEXPANSION prevents an environment variable that's set in a called script from returning to the caller.

Ie/
Script1.cmd

@echo off
set RET=%1
set %RET%="My return value"

Executed from the command prompt:

Script1.cmd MyVariable
set MyVariable

returns

"My return value"

Adding:

setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION

causes this behavior to fail.