Windows7 Batch,第一次For循环后如何中断 [英] Windows7 Batch, how to break after first For loop
本文介绍了Windows7 Batch,第一次For循环后如何中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个简单的脚本来检索作为IP给出的本地地址.
I'm writing a simple script to retreive my localhost address given as IP.
要获取我的IPv4地址(Win7),我编写了简单的FOR循环,但结果是我从最后一个循环而不是第一个获取了IP.
To get my IPv4 address (Win7) I've written simple FOR loop, but as a result i get the IP from last loop instead of first one.
这是批处理代码:
cls
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do (
set ip=%%b
)
set ip=%ip:~1%
echo %ip%
这将返回:
(set ip= 192.168.1.101 )
(set ip= 192.168.88.1 )
(set ip= 192.168.137.1 )
set ip=192.168.137.1
echo 192.168.137.1
192.168.137.1
我需要的是第一个循环的结果:
What i need is the result of first loop:
192.168.1.101
推荐答案
那该代码又没有任何循环呢?
And what about this code without any loop ?
@Echo off
For /f "tokens=2 delims= " %%a in ('arp -a ^|findstr /i "Interface"') do (set IP=%%a)
Echo The IP adress is : %IP%
pause
这篇关于Windows7 Batch,第一次For循环后如何中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文