Board logo

标题: [其他] 请教两种用批处理命令set设置变量的区别 [打印本页]

作者: dizimotong    时间: 2015-5-3 17:34     标题: 请教两种用批处理命令set设置变量的区别

看到别人的代码设置变量时,用了两种不同方式,具体如下:
  1. set a=this is a test
  2. set "a=this is a test"
复制代码
好像两种的输出结果都一样,想请教高手它们有什么区别,最好举例说明一下,谢谢了!
作者: CrLf    时间: 2015-5-3 17:42

在几种情况下有点差异,楼主感受一下...
  1. set a=3^2=9
  2. echo ["%a%"]
  3. set "a=3^2=9"  
  4. echo ["%a%"]
复制代码
  1. set a=this is a test   
  2. echo [%a%]
  3. set "a=this is a test"  
  4. echo [%a%]
复制代码
  1. set a=this" is a test
  2. echo [%a%]
  3. set "a=this" is a test
  4. echo [%a%]
复制代码

作者: dizimotong    时间: 2015-5-3 18:27

回复 2# CrLf

很感谢你的回复,通过这几个代码,我有了一定的了解。不过,还是要请问有没有相关的帖子或者什么文档关于这方面的文字描述,方便我日后查阅和更深入的了解。
作者: zhangzsky    时间: 2015-5-3 18:38

http://www.bathome.net/thread-14927-1-3.html
比较全面的,但好像未列出楼主所提。
引号不知道是否与路径引号类似,引号内空格等一些符号也设置为变量a的内容?
作者: ncatli    时间: 2015-5-3 23:27

多谢,也学习了
作者: CrLf    时间: 2015-5-4 01:01

主要区别是不加引号容易出现各种隐蔽错误,引号可以明确地界定变量名和变量内容,阅读起来也更直观




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2