On 19 Jun 10:27, Mark Rogers wrote:
This works: mac=$(ifconfig eth0 | grep -Eo '..:..:..:..:..:..' | sed -e 's/://g')
.. but I'm sure there's a better way. Suggestions?
Also, if I have something like: echotemplate="This is my MAC: (MAC)" mac=$(ifconfig eth0 | grep -Eo '..:..:..:..:..:..' | sed -e 's/://g') echo $(echo $echotemplate | sed -e "s/(MAC)/$mac/")
.. is there a better way to do the substitution in the last line? I can't swap the top two lines around (one is a user-defined setting at the top of the script, the value of $mac is calculated in the body of the script), otherwise I would just use echo "This is my MAC: $mac" .. which would be nice and easy! But I'm using this as a learning exercise.
How about:
mac=$(ip link show dev eth0 | sed -e '/link/ether/ { s#[ ][ ]*link/ether[ ][ ]*##; s# .*$##; p }; d;') echo "This is my MAC: ${mac//:}"
Done.
(works in bash, won't work in dash)