Ooooh, I never thought about binary file reading using "read" as the prime mover as I can easily work around hexdump, (or od), for my binary file handling.
Let me delve deeper and find a back door. <wink>
If I am defeated I will let you know...
I must be allowed the two character "\0" for any binary/byte zero however...
This will be really interesting for me - thanks...
While i appreciate the interesting discussion i think this is hardly "Unix for Dummies" stuff. I transfer this thread over to "Unix Experts". I hope you feel suitably honoured. ;-))
This is the best I can do. Although there is a lot of superfluous code the important bits can be seen. This uses a default Macbook Pro system using bash...
It looks like xxd was doing the lifting, not bash, with no reference to $REPLY (since you did 'while read' with no variable). Can you read, recognize and write a null in bash alone?
Yes and no. It is the only way I can get byte value zero into a string variable using only this default OSX install, as bash is not byte value zero friendly...
As for the xxd command, try and remove the file pointer after "done" and see what happens.
Try replacing it with say /dev/null too. I have absolutely no idea why /tmp/binary.file IS needed, but it is...
If you enter:-
It will end up the same as /tmp/binary.file...
I have just had another idea.
Let me experiment and see if this idea works...
I will explain after some experimention what the idea is/was, whether successful or not, after I have tried it...
There is a wealth of possibilities, between the readline options, stty raw, and IFS, but so many tools do not deal with null, it's hard to even test. If you bash "read =n 1" a null into a variable, is it hard to tell the variable is the empty string '' or ""?
To write it out, one might use the printf character option, treating it as a special case and providing the null as a zero char (int) value. Once you get to treating it as a special case, you can write it with something like "echo '\0\c' ".
$IFS characters are another challenge, but if you use "read -n 1" you could do your own $IFS processing if any, setting $IFS to '' or unsetting it.
Getting byte zero, in pseudo_zero mode, into the shell is easy as the Arduino Voltmeter DEMO below shows.
However I have attempted to put byte zero into a string variable as a single character and I now concede defeat. It is not possible with default commands to force value of byte zero into any variable, so a minimum of "\0", 2 bytes, is required to _emulate_ it...
Dear Moderator
I am not able to post any new thread or post reply to mine old thread.
Kindly help as i am stuck on one problem and needed suggestion.
Regards
Jaydeep (1 Reply)
Apologies for any typos, and IF this has been done before...
This is yet another building block. The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way.
I need this facility for a kids project I am... (0 Replies)
Hello *nix specialists,
Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)