/**************************************************************************************** shell MAC 地址 校驗* 說明:* 要對MAC地址進行校驗,記錄一下正則表達式寫法,有些方法在PC上驗證是可行的,但到了* 嵌入式產品上,可能就不一定能運行了。** 2016-11-15 深圳 南山平山村 曾劍鋒**************************************************************************************/一、參考文檔:1. BASH regex match MAC addresshttp://stackoverflow.com/questions/19959537/bash-regex-match-mac-address2. Best way to extract MAC address from ifconfig's outputhttp://stackoverflow.com/questions/245916/best-way-to-extract-mac-address-from-ifconfigs-output 二、測試shell腳本如下:macPath=/sys/bus/i2c/devices/3-0050/eeprommac=`grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' $macPath`if [ ${#mac} -eq 17 ]; thenecho "MAC Address: $mac"ifconfig eth0 hw ether $macelse ifconfig eth0 hw ether 70:b3:d5:10:6f:90fi
?