[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 变量名尾部为若干等号的 set 命令及变量扩展问题

本帖最后由 neorobin 于 2014-10-20 00:20 编辑

在 WIN7 64 位下

1.
  1. set _==5
  2. echo %_=%
  3. set /a %_=% + 3
复制代码
输出
  1. 5
  2. 8
复制代码
2.
  1. set _==5
  2. echo %_%
  3. echo %_=%
  4. set /a %_=% + 3
复制代码
输出
  1. =5
  2. %_=%
  3. Missing operand.
复制代码
3.
  1. set _==5
  2. echo %_=%
  3. echo %_%
  4. set /a %_=% + 3
复制代码
输出
  1. 5
  2. %_%
  3. 8
复制代码
以下代码做了一些测试:

当变量名尾部为若干个等号时, 例如:
$=====
_========
能否用 set 命令对这样的变量成功赋值? 如果成功赋值, 那么可以用怎样的形式做变量扩展

当在 WIN XP 32bit 下测试时, 未能对这样的变量成功赋值;

但当在 WIN7 64bit 下测试时, 某些形式 可以扩展, 但另一些形式却未成成功 扩展, 而其中的规律暂不明.

当以下划线 _ 为变量名首字符时, 尾部等号的个数为 1, 2, 5, 6, 10, 11, 14, 17, 20 以及超过 20 个时, 可成功扩展.

而当变量名首字符为 $ 时,  尾部等号的个数达到 20 以及超过 20 个时, 可成功扩展, 当首字符换成: @  #  ; 时, 也得到这样的结果

测试代码:
  1. @echo off & mode 160, 1000
  2. set _====================================================================================================VAL
  3. set $====================================================================================================VAL
  4. set #====================================================================================================VAL
  5. set @====================================================================================================VAL
  6. set ;====================================================================================================VAL
  7. REM will report: The syntax of the command is incorrect.
  8. set =====================================================================================================VAL
  9. echo _ is [%_%]
  10. echo _= is [%_=%]
  11. echo _== is [%_==%]
  12. echo _=== is [%_===%]
  13. echo _==== is [%_====%]
  14. echo _===== is [%_=====%]
  15. echo _====== is [%_======%]
  16. echo _======= is [%_=======%]
  17. echo _======== is [%_========%]
  18. echo _========= is [%_=========%]
  19. echo _========== is [%_==========%]
  20. echo _=========== is [%_===========%]
  21. echo _============ is [%_============%]
  22. echo _============= is [%_=============%]
  23. echo _============== is [%_==============%]
  24. echo _=============== is [%_===============%]
  25. echo _================ is [%_================%]
  26. echo _================= is [%_=================%]
  27. echo _================== is [%_==================%]
  28. echo _=================== is [%_===================%]
  29. echo _==================== is [%_====================%]
  30. echo _===================== is [%_=====================%]
  31. echo _====================== is [%_======================%]
  32. echo _======================= is [%_=======================%]
  33. echo _======================== is [%_========================%]
  34. echo _========================= is [%_=========================%]
  35. echo _========================== is [%_==========================%]
  36. echo _=========================== is [%_===========================%]
  37. echo _============================ is [%_============================%]
  38. echo _============================= is [%_=============================%]
  39. echo _============================== is [%_==============================%]
  40. echo _=============================== is [%_===============================%]
  41. echo _================================ is [%_================================%]
  42. echo _================================= is [%_=================================%]
  43. echo _================================== is [%_==================================%]
  44. echo _=================================== is [%_===================================%]
  45. echo _==================================== is [%_====================================%]
  46. echo _===================================== is [%_=====================================%]
  47. pause
  48. echo $ is [%$%]
  49. echo $= is [%$=%]
  50. echo $== is [%$==%]
  51. echo $=== is [%$===%]
  52. echo $==== is [%$====%]
  53. echo $===== is [%$=====%]
  54. echo $====== is [%$======%]
  55. echo $======= is [%$=======%]
  56. echo $======== is [%$========%]
  57. echo $========= is [%$=========%]
  58. echo $========== is [%$==========%]
  59. echo $=========== is [%$===========%]
  60. echo $============ is [%$============%]
  61. echo $============= is [%$=============%]
  62. echo $============== is [%$==============%]
  63. echo $=============== is [%$===============%]
  64. echo $================ is [%$================%]
  65. echo $================= is [%$=================%]
  66. echo $================== is [%$==================%]
  67. echo $=================== is [%$===================%]
  68. echo $==================== is [%$====================%]
  69. echo $===================== is [%$=====================%]
  70. echo $====================== is [%$======================%]
  71. echo $======================= is [%$=======================%]
  72. echo $======================== is [%$========================%]
  73. echo $========================= is [%$=========================%]
  74. echo $========================== is [%$==========================%]
  75. echo $=========================== is [%$===========================%]
  76. echo $============================ is [%$============================%]
  77. echo $============================= is [%$=============================%]
  78. echo $============================== is [%$==============================%]
  79. echo $=============================== is [%$===============================%]
  80. echo $================================ is [%$================================%]
  81. echo $================================= is [%$=================================%]
  82. echo $================================== is [%$==================================%]
  83. echo $=================================== is [%$===================================%]
  84. echo $==================================== is [%$====================================%]
  85. echo $===================================== is [%$=====================================%]
  86. pause
复制代码
输出结果
  1. The syntax of the command is incorrect.
  2. _ is [===================================================================================================VAL]
  3. _= is [==================================================================================================VAL]
  4. _== is [=================================================================================================VAL]
  5. _=== is []
  6. _==== is []
  7. _===== is [==============================================================================================VAL]
  8. _====== is [=============================================================================================VAL]
  9. _======= is []
  10. _======== is []
  11. _========= is []
  12. _========== is [=========================================================================================VAL]
  13. _=========== is [========================================================================================VAL]
  14. _============ is []
  15. _============= is []
  16. _============== is [=====================================================================================VAL]
  17. _=============== is []
  18. _================ is []
  19. _================= is [==================================================================================VAL]
  20. _================== is []
  21. _=================== is []
  22. _==================== is [===============================================================================VAL]
  23. _===================== is [==============================================================================VAL]
  24. _====================== is [=============================================================================VAL]
  25. _======================= is [============================================================================VAL]
  26. _======================== is [===========================================================================VAL]
  27. _========================= is [==========================================================================VAL]
  28. _========================== is [=========================================================================VAL]
  29. _=========================== is [========================================================================VAL]
  30. _============================ is [=======================================================================VAL]
  31. _============================= is [======================================================================VAL]
  32. _============================== is [=====================================================================VAL]
  33. _=============================== is [====================================================================VAL]
  34. _================================ is [===================================================================VAL]
  35. _================================= is [==================================================================VAL]
  36. _================================== is [=================================================================VAL]
  37. _=================================== is [================================================================VAL]
  38. _==================================== is [===============================================================VAL]
  39. _===================================== is [==============================================================VAL]
  40. Press any key to continue . . .
  41. $ is [===================================================================================================VAL]
  42. $= is []
  43. $== is []
  44. $=== is []
  45. $==== is []
  46. $===== is []
  47. $====== is []
  48. $======= is []
  49. $======== is []
  50. $========= is []
  51. $========== is []
  52. $=========== is []
  53. $============ is []
  54. $============= is []
  55. $============== is []
  56. $=============== is []
  57. $================ is []
  58. $================= is []
  59. $================== is []
  60. $=================== is []
  61. $==================== is [===============================================================================VAL]
  62. $===================== is [==============================================================================VAL]
  63. $====================== is [=============================================================================VAL]
  64. $======================= is [============================================================================VAL]
  65. $======================== is [===========================================================================VAL]
  66. $========================= is [==========================================================================VAL]
  67. $========================== is [=========================================================================VAL]
  68. $=========================== is [========================================================================VAL]
  69. $============================ is [=======================================================================VAL]
  70. $============================= is [======================================================================VAL]
  71. $============================== is [=====================================================================VAL]
  72. $=============================== is [====================================================================VAL]
  73. $================================ is [===================================================================VAL]
  74. $================================= is [==================================================================VAL]
  75. $================================== is [=================================================================VAL]
  76. $=================================== is [================================================================VAL]
  77. $==================================== is [===============================================================VAL]
  78. $===================================== is [==============================================================VAL]
  79. Press any key to continue . . .
复制代码
1

评分人数

    • plp626: 跟踪一下; 好久没看到这样的帖子了技术 + 1

回复 7# CrLf
不会汇编  55555~~~正在看  买到了 王爽的教材  确实很通俗易懂

TOP

回复 5# Linuxer


    为什么 % 看起来这么像肥皂

回复 6# neorobin


    明天用 od 试着跟一下...

TOP

这个想更深入点了解, 我想得用 反编译 和 内存分析 工具, 是很伤脑筋的工作吧.

我现在只能停留在知道有这个现象存在了, 不小心扎到手时, 就会记起来这里确实有个钉子的.

TOP

回复 4# CrLf
  1. echo %a=b=c
复制代码
楼上的,你%掉了。
1

评分人数

    • CrLf: 感谢指正~技术 + 1
问题解决后,请在标题前面注明[已解决],并给回答者加分——化繁为简,提高工作效率!

TOP

本帖最后由 CrLf 于 2014-10-22 20:25 编辑

我的测试是这样的:
  1. set a=b=c=d
  2. echo %a%
  3. echo %a=b%
  4. echo %a=b=c%
复制代码

TOP

1、2、3勉强还能看一下。。。再往下,,,,已经晕了。
问题解决后,请在标题前面注明[已解决],并给回答者加分——化繁为简,提高工作效率!

TOP

碰到过这类问题,测试角度不一样,但同样摸不着头脑...

TOP

返回列表