I want to build a bash program that can read a file, like a *.bin and print all its hexadecimal numbers, as ‘hex’ editors do. Where I can start?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit: Added “bytestream” functionality. If the script name contains the word “stream” (e.g. it’s a symlink such as
ln -s bash-hexdump bash-hexdump-streamand run as./bash-hexdump-stream), it will output a continuous stream of hex characters representing the contents of the file. Otherwise its output will look likehexdump -C.It takes a bunch of trickery since Bash isn’t really good at binary:
The apostrophe trick is documented here. The relevant part says:
Here is some output from the script showing the first few lines of my
/bin/bashplus a few more: