home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 68,790 of 68,980   
   Herbert Kleebauer to Anton Shepelev   
   Re: ENDLOACAL & CALL ... fails to expand   
   15 May 24 20:06:58   
   
   From: klee@unibwm.de   
      
   On 15.05.2024 18:36, Anton Shepelev wrote:   
      
   > 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: []   
      
   > Why can't REF be expanded on the last line as in the first   
   > example?   
      
   Because the "call echo" is used to perform a delayed expansion.   
   After the "call" is evaluated, the line becomes:   
      
   ENDLOCAL & ECHO REF points to: [%VAL%]   
      
   But after ENDLOCAL is executed, VAL is no longer defined.   
   If you define VAL outside the SETLOCAL, you get this value:   
      
      
   SET VAL=2   
   SETLOCAL   
   SET VAL=1   
   SET REF=VAL   
   ENDLOCAL & CALL ECHO REF points to: [%%%REF%%%]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca