On 19/06/12 11:42, Brett Parker wrote:
How about: mac=$(ip link show dev eth0 | sed -e '/link\/ether/ { s#[ ][ ]*link/ether[ ][ ]*##; s# .*$##; p }; d;')
Thanks, nice to have an alternative that makes better use of sed and loses grep. What is the meaning/reasoning behind "[ ][ ]*"? My interpretation of it is just "one or more spaces", is that correct? Is "[ ]" just a style preference to make it easier to read than " *", or am I missing something? Other than that I have managed to parse it in my head after a couple of attempts! At the moment I've adapted it to: mac=$(ip link show dev eth0 | sed -e '/link\/ether/ { s# *link/ether *##; s# .*$##; p }; d;') .. as I don't see "zero-or-more spaces" being too general, but that makes assumptions about my understanding of your version....
echo "This is my MAC: ${mac//:}"
The problem with this is that it puts the "template" at the point in the code where it's used, where I want to be able to define the template in the user-config part of the script at the top, and # Config section of script template="This is my MAC: ${mac//:}" # Main script, do not edit # Lots of stuff in here..... mac=$(ip link show dev eth0 | sed -e '/link\/ether/ { s#[ ][ ]*link/ether[ ][ ]*##; s# .*$##; p }; d;') echo $template doesn't work as the variable expansion happens before it is set. Mark -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450 Registered in England (0456 0902) 21 Drakes Mews, Milton Keynes, MK8 0ER