What is the best way to extract the MAC address from ifconfig\'s output?
Sample output:
bash-3.00# ifconfig eth0
eth0 Link
Since the OP's example refers to Bash, here's a way to extract fields such as HWaddr without the use of additional tools:
x=$(ifconfig eth0) && x=${x#*HWaddr } && echo ${x%% *}
In the 1st step this assigns the ouput of ifconfig to x. The 2nd step removes everything before "HWaddr ". In the final step everything after " " (the space behind the MAC) is removed.
Reference: http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion