我去,我才知道
ip(8) 有个 -j 可以输出 json 格式,比如获取一个网络接口的二层地址,我之前一直是
$ s ip -n node2 -br l sh nsim1 | awk '{print $3}'
72:b2:7a:99:fe:f4
用 -j | jq 心里有底气得多:
$ s ip -n node2 -j l sh nsim1 | jq -r '.[0].address'
72:b2:7a:99:fe:f4
从此再也不内耗了,再让我看到 awk/grep/sed 切字符串我直接使用纵欲卡
🤬