要找出主機的IP位址,方法有許多個,其中一個最簡單的是利用ifconfig

#! /bin/bash
shopt -s -o nounset
ListIPcmd="/sbin/ifconfig"

IP=$($ListIPcmd | grep 'inet addr:' | grep -v '127.0.0.1' | awk '{print $2}' | awk -F:  '{print $2}')
echo $IP
Last modification:April 6, 2018
If you think my article is useful to you, please feel free to appreciate