因为batch实际上没有into,所以我不得不使用set /a来解决这个问题。这里我有一个代码段(来自batch),它计算一个数值表达式并将其设置为一个字符串:
@echo off
set test=|set /a 12-10
pause我的问题是,这实际上是打印"test“字符串。这非常不方便,因为我以后可能需要更改字符串。有没有办法绕过这一点(除了一大堆cls)?
发布于 2012-03-26 04:49:50
我相信
set /a test=12-10 > NUL是你想要的--你的版本根本没有设置test。
C:\temp>type t.cmd
@echo off
set /a test=1+5-21 > NUL
echo Test is: %test%
C:\temp>t.cmd
Test is: -15你甚至可以像这样做间接赋值:
C:\temp>type t.cmd
@echo off
setlocal
echo before: %mything%
set var=mything
set /a %var%=4+3
echo after: %mything%
C:\temp>t.cmd
before:
after: 7发布于 2012-03-26 05:10:40
这将为您提供一些想法:
@echo off
set test=|set /a 16-10
ECHO.
SET /A y=12 - 10
ECHO.y = '%y%'
pause>nulhttps://stackoverflow.com/questions/9863813
复制相似问题