bash script: converted hex values to string causing loss of bytes

8 views
Skip to first unread message

deb

unread,
Jan 11, 2015, 1:56:00 PM1/11/15
to unix-...@googlegroups.com
me (deb change
Jan 11 (4 hours ago)
Hi,

I have a requirement of calling command in bash script which takes 12 bytes string.
I need to send the below value in that string:

in hex each byte separated by : \x23,\x07,\0x01,\x00,\x80,\x00,\x00,\x00,\x00,\x00,\x00,\x00

i need to convert each of these hex values to ascii and form a 12 byte length string and send it as option to my command.

i tried this way:

bytes1=$(printf "\x23")
bytes2=$(printf "\x07")
bytes3=$(printf "\x01")
bytes4=$(printf "\x00")
bytes5=$(printf "\x80")

cmd=$(echo $bytes1$bytes2$bytes3$bytes4$bytes5$bytes4$bytes4$bytes4$bytes4$bytes4$bytes4$bytes4)
size=$(echo ${#cmd})
echo "string length= $size"

i get length as 4

Probably bytes having \x00 causing this problem. Could you please suggest and help me on it to create the correct string.

Thanks
deb
Reply all
Reply to author
Forward
0 new messages