[lug] Problem with bash script

Stephen Queen svqueen at gmail.com
Fri Oct 17 09:59:06 MDT 2008


I have a device that is called /dev/nspi2
I need to write some hexadecimal numbers directly to it using a bash
script. The script name is ld_config

$ ./ld_config > /dev/nspi2

$ cat ld_config
#!/bin/bash

/bin/echo -ne $'\x02'$'\x03''\0''\0'$'\x05''\0'$'\x33''\0'

if I pipe it to od like

$ ./ld_config | od -t x1 #the output should look like
0000000 02 03 00 00 05 00 33 00
0000010

instead it looks like
0000000 02 03 00 00 05 03 00
0000007

Byte 5 which is suppose to be 00 is missing and byte 6 is 03 instead of 33.

If I change the script ever so slightly so that it now looks like this
$ cat ld_config
#!/bin/bash

/bin/echo -ne $'\x02'$'\x03''\0''\0'$'\x05''\0'$'\x23''\0'

(I changed byte 6 from $'\x33' to $'\x23')
The output now looks like
$ ./ld_config | od -t x1
0000000 02 03 00 00 05 00 23 00
0000010

which is correct.
Any comments or suggestions on how to correct this so I can get the
hex numbers I want?



More information about the LUG mailing list