当我运行此代码段时,当我键入“ |”时它会炸毁 字符
SET /P _test=Enter your value:
echo %_test%
Enter your value: Hello|World
'World' is not recognized as an internal or external command,
operable program or batch file.
我希望%_test%包含提供的文本Hello | World,有什么想法吗?
安全地回显任意字符串的唯一方法是使用延迟扩展:
set /P _test="Enter your value: "
setlocal EnableDelayedExpansion
echo(!_test!
endlocal
奇数看语法echo(
允许甚至是空字符串,也琴弦on
,off
或者/?
,否则会被解释为关键字或选项echo
命令。
关于变量_test
之后的变化以后setlocal
会丢失endlocal
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句