将第三个八位从IP地址隔离,然后将其放入变量中.这条线正在做第四.使用/bin/bash MacOS/AppleScri



脚本:

read IP SIP < <(exec ifconfig en0 | awk '/inet / { t = $2; sub(/.*[.]/, "", t); print $2, t }')

我正在尝试隔离第三个八位骨xxx.xxx.000.xxx并将其放入变量中。帮助?谢谢!

以下将将第三个八位位设置为 thirdOctet variable

set thirdOctet to do shell script "ifconfig en0 | awk -F . '/inet /{print $3}'" 

简单的applescript解决方案

set ipv4Address to do shell script "ifconfig en0 | awk '/inet / {print $2}'"
set {TID, text item delimiters} to {text item delimiters, "."}
set thirdOctet to text item 3 of ipv4Address
set text item delimiters to TID
display dialog thirdOctet buttons {"OK"} default button "OK"