最短的Windows批处理文件代码,可将文件的第一行设置为变量? [英] Shortest Windows batch file code to get first line of a file set to a variable?
问题描述
我正在寻找可能的最短代码,以获取文本文件的第一行并将其设置为Windows中的变量.
I am looking for the shortest amount of code possible that will get the first line of a text file and set it to a variable in Windows.
在StackExchange网站上的其他线程中有很多此类事情的例子,但我不正在寻找如何循环浏览并显示文件中的所有行.我想要的只是简单获得第一行.
There are lots of examples of this kind of thing in other threads on this StackExchange site but I am not looking for how to loop through and display all lines in a file. What I want is to just simply get the first line.
推荐答案
set /p var= <Text.txt
echo %var%
引用自: http://forums .techguy.org/software-development/551867-batch-file-read-line-text.html 具有讽刺意味的是,海报发布者能够获得第一行,但希望循环浏览整个文件!
Referenced from: http://forums.techguy.org/software-development/551867-batch-file-read-line-text.html Ironically the poster is able to get the first line but wanted to loop through the whole file!
这篇关于最短的Windows批处理文件代码,可将文件的第一行设置为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!