Why can't I access a variable named __CD__ on Windows 7?

前端 未结 5 2178
渐次进展
渐次进展 2020-12-01 14:47

Note - this question is based on behavior observed on Windows 7. I believe the behavior applies to all other versions from Vista onward. Based on MC ND\'s answer, and Fo

5条回答
  •  死守一世寂寞
    2020-12-01 15:08

    I can't see the cause why a userdefined __cd__ is different to a user defined cd variable.
    But I made some tests.

    setlocal EnableDelayedExpansion
    echo #0 %__cd__%
    if defined __cd__ echo #1 It's defined
    set __cd__=1234
    echo #2 %__cd__%
    echo #3 !__cd__!
    call echo #4 %%__cd__%%
    echo #5 %__cd__:x=y%
    echo #6 !__cd__:x=y!
    if defined __cd__ echo #7 It's defined
    set __cd__
    set /a result=__cd__
    echo #7 %result%
    

    So there are three interesting points.

    1. The test with if defined is always positive
    2. set can echo the user defined variable
    3. set /a can access the user defined variable

提交回复
热议问题