I must give kudos to @rubo77 above for a pure-shell (unless you count printf) answer above, which I was seeking.
This adds a bit of sed to:
(a) elide any leading zeroes in each 16-bit chunk; and
(b) elide any further all-zero chunks at the start of the IID
...as per common conventions for address brevity.
mac_to_eui64() {
IFS=':'; set $1; unset IFS
echo "fe80::$(printf %x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6" |
sed -E 's/:0+/:/g; s/:{3,}/::/; s/:$/:0/'
}
Note that if you wished to repurpose this for other (arbitrary) prefixes, which you might since EUI-64 can be used in any scope (although it's advised not to use it for global addresses for privacy reasons), you'd need a slightly more convoluted sed script. That's because the fe80::
prefix already contains three zero-chunks (elided to the double-colon) adjacent to the start of the IID. Thus even if the IID's first chunk is all-zeroes (that is, if the MAC started with 02:00
), it would be elided too. The EUI-64 format only leaves one further chunk that could be all-zero -- the last one -- which the script above adds back in as a single zero. Other prefixes might require one to leave a single zero between two colons.