Unexpected concatenation of shell variables

When I try executing the following lines of code on shell-

#!/bin/sh
mc=XX:XX:XX:XX; dd bs=1 count=2 if=/dev/random 2>/dev/null |hexdump -v -e '/1 ":%02X"'
echo $mc

the output I get is

:04:CCXX:XX:XX:XX

,i.e. the X’s are concatenated at the end instead of the beginning. I also tried this (as mentioned in an answer on SO ) –

#!/bin/sh
mc=XX:XX:XX:XX
mc=$mc dd bs=1 count=2 if=/dev/random 2>/dev/null |hexdump -v -e '/1 ":%02X"'
echo $mc

I still get the same output. What am I missing here ? I am a shell novice so please forgive me for any obvious mistakes


Source: shell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.