DOS批处理文件 - 设置变量&Q​​UOT;若"块 [英] DOS Batch file - set variable in "if" block

查看:174
本文介绍了DOS批处理文件 - 设置变量&Q​​UOT;若"块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的程序总是呼应机器XYZ不论该IF语句计算结果为TRUE或FALSE:

The following program always echoes "machine-xyz" irrespective of whether the "IF" statement evaluates to TRUE or FALSE:

 @echo off
  set dropLoc=machine-abc
  if %computername% == "xyz" then (
     set dropLoc=machine-xyz
  )
  echo %dropLoc%

我如何使这项工作?

How do I make this work?

推荐答案

您得到了 SET 语法正确的第一次,为什么你决定写别的东西第二时间是圆的?此外,您必须添加的比较两侧的引号。不像其他的脚本间preters,引号不是特殊批次间preTER。

You got the SET syntax right the first time, how come you decided to write something else the second time round? Also, you have to add the quotation marks on both sides of the comparison. Unlike in other script interpreters, quotation marks aren't special for the batch interpreter.

@echo off

rem Change this for testing, remove for production
set computername=xyz

set dropLoc=machine-abc

if "%computername%" == "xyz" (
  set dropLoc=machine-xyz
)

echo %dropLoc%

这篇关于DOS批处理文件 - 设置变量&Q​​UOT;若"块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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