On 28/07/17 07:22 AM, rpj...@crashcourse.ca wrote:
> 
>   OK, this exercise should be a bit trickier -- given a character MAC
> address, how can I break it into individual hex chars for writing to
> EEPROM? So the script takes the argument, say, "A0:B1:C2:D3:E4:F5",
> and I need to, one nibble at a time, get the value 0x0A, 0x0, 0x0B, 0x01
> and so on.
> 
>   (Doesn't matter if the invoker wants to put the colons in or not, I
> can just run the string through "tr -d ':'" to deal with that.)
> 
>   As earlier, I can always loop through each character in the MAC address,
> but I'm wondering if there's some clever "printf" format that can
> do that all at once.

printf doesn't cut up a string in the way you need, it truncates it so
not much help there.

#given
MAC=00:11:aa:bC:dE:0f
mac=$(echo "${MAC,,}"|tr -d ':-')
echo -n "$mac => "
#you can
echo "$mac"|sed 's/../0x& /g'
#or
for i in $(seq 0 2 10 );do echo -n "0x${mac:$i:2} ";done

or any variant of from the character loop


> 
> rday
> 
> _______________________________________________
> Linux mailing list
> Linux@lists.oclug.on.ca
> http://oclug.on.ca/mailman/listinfo/linux


_______________________________________________
Linux mailing list
Linux@lists.oclug.on.ca
http://oclug.on.ca/mailman/listinfo/linux

Reply via email to