Bash script that prints out contents of a binary file, one word at a time,
without xxd
I'd like to create a BASH script that reads a binary file, word (32-bits)
by word and pass that word to an application called devmem.
Right now, I have:
...
for (( i=0; i<${num_words}; i++ ))
do
val=$(dd if=${file_name} skip=${i} count=1 bs=4 2>/dev/null)
echo -e "${val}" # Weird output...
devmem ${some_address} 32 ${val}
done
...
${val} has some weird (ASCII?) format character representations that looks
like a diamond with a question mark.
If I replace the "val=" line with:
val=$(dd ... | xxd -r -p)
I get my desired output.
What is the easiest way of replicating the functionality of xxd using BASH?
Note: I'm working on an embedded Linux project where the requirements
don't allow me to install xxd.
This script is performance driven, please correct me if I'm wrong in my
approach, but for this reason I chose (dd -> binary word -> devmem)
instead of (hexdump -> file, parse file -> devmem). - Regardless of the
optimal route for my end goal, this exercise has been giving me some
trouble and I'd very much appreciate someone helping me figure out how to
do this.
Thanks!
No comments:
Post a Comment