shell 脚本学习-回显服务器ip
作者:互联网
touch app.sh
vi app.sh
function ipaddr() {
ip=`ip addr | grep -v '\(docker\|br-\|kube\|nodelocaldns\|tunl\)'|grep -E '([0-9]{1,3}[.]){3}[0-9]{1,3}'|grep inet|grep global|grep -v virbr|awk '{print $2}'|head -1` && ip=${ip%/*}
echo $ip
}
function main() {
ipaddr();
}
:wq
chmod +x app.sh
./app.sh
标签:function,shell,grep,回显,ip,app,ipaddr,sh 来源: https://www.cnblogs.com/hanks-mimi/p/16348664.html