批量输出,每个字符串后都有空格 [英] batch outputting with space after each string
本文介绍了批量输出,每个字符串后都有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我目前有这段代码可以将来自不同文本文件的不同文本转换为变量,然后输出为一个文件:
Hey i currently have this code to turn different text from different text files into variables then output into one file:
@echo off
echo system starting..
cls
echo grabbing versions
cd C:\Scripts\Bamboo
FOR /F "tokens=1 delims==" %%n IN (CurrentBuild.txt) DO SET build-version-number=%%n
cd C:\Users\Administrator\bamboo-home\xml-data\build-dir\MC-CC-MAIN
FOR /F "tokens=1 delims==" %%n IN (MinecraftVersion.txt) DO SET minecraft-version-number=%%n
FOR /F "tokens=1 delims==" %%n IN (ForgeVersion.txt) DO SET forge-version-number=%%n
FOR /F "tokens=1 delims==" %%n IN (ModVersion.txt) DO SET mod-version-number=%%n
cls
echo setting versions to variables
set mod-version=mod_version = %mod-version-number%
set forge-version=forge_version = %forge-version-number%
set build-version=build_version = %build-version-number%
set minecraft-version=minecraft_version = %minecraft-version-number%
cls
echo outputing variables to build.properties
del build.properties
@echo %minecraft-version% >> build.properties
@echo %forge-version% >> build.properties
@echo %mod-version% >> build.properties
@echo %build-version% >> build.properties
cls
echo done, exiting inject script
exit
但是输出中的每个空格后面都有空格(whitline):
but the output has spaces (whitline) after each one:
"minecraft_version = 1.7.10 "
"forge_version = 10.13.2.1291 "
"mod_version = v1.0 "
"build_version = 33 "
不确定为什么会这样.
推荐答案
它是>
或>>
重定向器之前的空间.删除它如下(关于 dbenham的有益评论进行的编辑):
It is the space preceding the >
or >>
redirector. Remove it as follows (edited in regard of dbenham's benefitting comment):
(@echo %minecraft-version%)>> build.properties
或
>> build.properties (@echo %minecraft-version%)
说明:
-
如果变量
-
@echo %minecraft-version%>> build.properties
可能会中断输出; -
>> build.properties @echo %minecraft-version%
不够用,因为该行可能包含不需要的(被遗忘的)尾随空格.
%minecraft-version%
以单个数字结尾结束,则@echo %minecraft-version%>> build.properties
could break output if the variable%minecraft-version%
ends with a single digit preceded with a space;>> build.properties @echo %minecraft-version%
does not suffice as the line could contain an unwanted (forgotten) trailing space.
此外,要完全控制变量名和值中的前导和尾随空格,请在set
命令中使用双引号,如下所示:
Moreover, to keep full control on leading and trailing spaces in variable names and values, use double quotes in set
command as follows:
set "variable=value"
思考其他人:
set "variable= this value contains a leading space"
set "variable= this value surrounded with spaces "
set "variable=this value contains a trailing space "
set "variable =this variable name contains a trailing space"
已应用于脚本中的某些命令:
Applied to some commands in your script:
FOR /F "tokens=1 delims==" %%n IN (ModVersion.txt) DO SET "mod-version-number=%%n"
:::
set "mod-version=mod_version = %mod-version-number%"
等
这篇关于批量输出,每个字符串后都有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文