Wel, in a null terminated string application, null is always '' the empty string, as it reterminates the string, just as a strcpy of a 5 byte plus null string into a 20 byte buffer initialized with 19 spaces and a null creates a string length of 5.
Now, is it the only character that is equal to '' the empty string? Does read differentiate that from EOF in a while read loop?
Too many aliases. Whatever is or defaults to IFS is indistinguishable from null:
Last edited by DGPickett; 09-06-2013 at 07:13 PM..
There is possibly one _bug_ I can see in both my and your attempts is character 92, "\"
causing a pseudo escape on the next binary character it sees when running an
"somevar=echo -e......" into it more than once.
It also seems your 0x09 and 0x0A become NULL too.
I can understand why 0x0A _might_ occur but not 0x09, (Tab).
Does read differentiate that from EOF in a while read loop?
On a binary file with single byte zero(s) uisng the default bash "read", yes, but on a
binary_string_variable, hmmm, hard to judge as placing byte zero into a variable is
not possible at this point.
Ignoring "read" FTTB I am going to try and force byte zero into the middlie of
a "Hello World." string, i.e. the space replaced with 0x00...
---------- Post updated 07-09-13 at 11:21 AM ---------- Previous update was 06-09-13 at 10:58 PM ----------
I tried this out from the command line and......
"read" has brought in the correct length of "Hello World.", 12, with the space shown as
character 0, but its file length is actually 13 characters in size...
So to return back to 13 characters again using pseudo-zero 2 backslashes will be needed
inside the file now making the file length 14.
This is a real killer for binary_string to file and back again manipulation.
I think the only way to account for binary zero is to use "\0" two characters and detect
those two characters inside the binary_string something like this...
The problem is that there may be two genuine independent "\" and "0" characters side
by side and not related to binary zero at all, just independent characters...
So, you can see shell is not a binary capable tool. Some bytes it can handle, but nulls, linefeeds, white space are problematic. But you can write trivial C to support it, like at tool that just does a tr of null to something else, trnull:
Last edited by DGPickett; 09-17-2013 at 04:34 PM..
The problem is the same as mine, in that address 0x41 is also a(n) "!" so is this a binary zero or a real "!".
There is no way of knowing so I thought of using "@@" to substitute for binary zero as "\@" would present a similar problem as my "\0", but, would import into "read" easily.
But again "@@" may actually exist as real characters and not a substitution but at least it is starter approach to emulating binary zero...
All the 256 holes are always taken, so if your milieu does not have a limited character set, then you are right, the only escape is into longer strings for short characters, but then only context tells you that is the sort of file you have. That's why JAVA and xml use UTF-8 and label the content type. It started as a 'code page' discussion, a.k.a "what drum is on the printer".
There are apps for UNIX around that let you deal with image files like jpg and gif in text files of text numbers, like a decimal dump of a bmp file. I suppose if you run binary through the right dump you can then process it in shell back to a binary file.
Last edited by DGPickett; 09-18-2013 at 05:37 PM..
Whenever you escape null to \0 you must minimally escape \ to \\. IFS has to have one character in it, so if you put in newline only, \n, a utility that escaped just those three would make data shell friendly.
Forgot the exit(0) for no error stdout EOF last time!
Last edited by DGPickett; 09-19-2013 at 05:44 PM..
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)