gpt4 book ai didi

windows - 批处理脚本 : Why does this print "= instead of the empty string?

转载 作者:可可西里 更新时间:2023-11-01 11:17:13 24 4
gpt4 key购买 nike

我正在尝试使用 Batch 中的参数扩展删除某些文本中的引号。谁能告诉我这是为什么:

@echo off
setlocal

set args=%*
echo %args:"=%

prints "= 而不是什么都没有?据我所知,%args:"=% 应该将所有引号替换为空,所以我不明白为什么这正在发生。

任何帮助将不胜感激,谢谢!

编辑:为了澄清,我没有将任何参数传递给批处理脚本。

最佳答案

这是您不向脚本传递任何参数时得到的结果。

如果未定义args,则%args:"=%展开如下:

  • %args:被当做一个不存在的变量展开,变成nothing
  • "= 被当作它自己
  • %(单独的百分比)被剥离

这并不直观,但这恰好是 cmd.exe 的工作方式。参见 https://stackoverflow.com/a/7970912/1012053了解更多信息。

您可以通过使用 if defined 来防止这个问题

@echo off
setlocal

set args=%*
if defined args echo %args:"=%

关于windows - 批处理脚本 : Why does this print "= instead of the empty string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36192919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com