Anton Shepelev
2024-05-15 16:36:34 UTC
Hello, all.
According to
<https://ss64.com/nt/endlocal.html>
ENDLOCAL can be used with `& CALL SET' in order to pass
local variables outside, because the script is executed
line-by-line and the expantion performed before the local
scope is exited. I cannot, however, take advantage of this
feature with nested expanstion. The following script:
@ECHO OFF
SETLOCAL
SET VAL=1
SET REF=VAL
ENDLOCAL & CALL ECHO REF points to: [%%%REF%%%]
Prints:
REF points to: []
whereas I expected it to print:
REF points to: [1]
I can get the desired behavior only by expanding REF
beforehand:
@ECHO OFF
SETLOCAL
SET VAL=1
SET REF=VAL
CALL SET UNREF=%%%REF%%%
ENDLOCAL & CALL ECHO REF points to: [%UNREF%]
Why can't REF be expanded on the last line as in the first
example?
According to
<https://ss64.com/nt/endlocal.html>
ENDLOCAL can be used with `& CALL SET' in order to pass
local variables outside, because the script is executed
line-by-line and the expantion performed before the local
scope is exited. I cannot, however, take advantage of this
feature with nested expanstion. The following script:
@ECHO OFF
SETLOCAL
SET VAL=1
SET REF=VAL
ENDLOCAL & CALL ECHO REF points to: [%%%REF%%%]
Prints:
REF points to: []
whereas I expected it to print:
REF points to: [1]
I can get the desired behavior only by expanding REF
beforehand:
@ECHO OFF
SETLOCAL
SET VAL=1
SET REF=VAL
CALL SET UNREF=%%%REF%%%
ENDLOCAL & CALL ECHO REF points to: [%UNREF%]
Why can't REF be expanded on the last line as in the first
example?
--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments