【发布时间】:2015-09-14 14:56:19
【问题描述】:
我只想阅读 netstat 的第一行,即解释每列含义的那一行:
Proto Local Address Foreign Address State
但是,当我执行以下操作时:
netstat | egrep -i "^\s*(tcp|udp)" | {
read line
echo 'Here is the first line ' $line
}
我只得到第一行连接:
Here is the first line TCP <Local_addr> <Foreign_addre> ESTABLISHED
我怎样才能得到那一行?
我在 Windows 7 机器上运行 Cygwin。谢谢。
【问题讨论】:
-
我个人不会为此目的使用
read- 我会找到一种方法来提取那一行并将其直接分配给一个变量。示例:line="$(netstat -n | sed -n 2p)"