本文介绍了我怎么能逃过感叹号!在 cmd 脚本中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 cmd 脚本中设置 setlocal ENABLEDELAYEDEXPANSION 时,有什么办法可以避免 !我想用作命令的参数?

When I have setlocal ENABLEDELAYEDEXPANSION set in a cmd script is there any way I can escape a ! that I want to use as a parameter to a command?

@echo off
setlocal ENABLEDELAYEDEXPANSION
echo I want to go out with a bang!
echo I still want to go out with a bang^!

推荐答案

要在启用延迟扩展的情况下批量使用解释点,您必须先将解释点添加到禁用它的变量中.请参阅以下具有 DISABLEDELAYEDEXPANSIONENABLEDELAYEDEXPANSION 状态的示例.

To use an explanation point in batch with Delayed Expansion enabled, you must first add the explanation point to a variable with it disabled. See the below example with both DISABLEDELAYEDEXPANSION and ENABLEDELAYEDEXPANSION state.

@echo off
setlocal DISABLEDELAYEDEXPANSION
set DB_password=encrypt!Pws
echo %DB_password%
SETLOCAL ENABLEDELAYEDEXPANSION
echo !DB_password!

这篇关于我怎么能逃过感叹号!在 cmd 脚本中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:23