参考:https://www.cnblogs.com/starof/p/4153663.html
补充:
linux加载网络配置文件:/usr/share/bash-completion/bash_completion
# This function completes on configured network interfaces
#
_configured_interfaces()
{
if [[ -f /etc/debian_version ]]; then
# Debian system //Debian系列:Debian、Ubuntu等
COMPREPLY=( $( compgen -W "$( sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p'\
/etc/network/interfaces )" -- "$cur" ) )
elif [[ -f /etc/SuSE-release ]]; then
# SuSE system
COMPREPLY=( $( compgen -W "$( printf '%s\n' \
/etc/sysconfig/network/ifcfg-* | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
elif [[ -f /etc/pld-release ]]; then
# PLD Linux
COMPREPLY=( $( compgen -W "$( command ls -B \
/etc/sysconfig/interfaces | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
else
# Assume Red Hat
COMPREPLY=( $( compgen -W "$( printf '%s\n' \
/etc/sysconfig/network-scripts/ifcfg-* | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
fi
}
# Local IP addresses.
#
_ip_addresses()
{
local PATH=$PATH:/sbin
COMPREPLY+=( $( compgen -W \
"$( { LC_ALL=C ifconfig -a || ip addr show; } 2>/dev/null |
sed -ne 's/.*addr:\([^[:space:]]*\).*/\1/p' \
-ne 's|.*inet[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p' )" \
-- "$cur" ) )
}