处理 Windows 批处理脚本中的引号 [英] Dealing with quotes in Windows batch scripts

查看:42
本文介绍了处理 Windows 批处理脚本中的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 批处理文件中,当您执行以下操作时:

In a Windows batch file, when you do the following:

set myvar="c:我的音乐和视频"

变量 myvar 与引号一起存储.老实说,我觉得这很愚蠢.引号只是为了说明字符串的开始和结束位置,而不是作为值本身的一部分存储.
我怎样才能防止这种情况发生?

the variable myvar is stored with the quotes included. Honestly I find that very stupid. The quotes are just to tell where the string begins and ends, not to be stored as part of the value itself.
How can I prevent this from happening?

谢谢.

推荐答案

set "myvar=c:my music & videos"

注意引号在 myvar 之前开始.其实就是这么简单.旁注:除非用引号括起来,否则 myvar 之后无法回显,因为 &将被读取为命令分隔符,但它仍可用作路径.

Notice the quotes start before myvar. It's actually that simple. Side note: myvar can't be echoed afterwards unless it's wrapped in quotes because & will be read as a command separator, but it'll still work as a path.

http://ss64.com/nt/set.html 在变量名可以包括空格"

http://ss64.com/nt/set.html under "Variable names can include Spaces"

这篇关于处理 Windows 批处理脚本中的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆