As bash cannot cope with a byte value of zero inside a variable then this is a workaround.
This code is a DEMO to show how to create a _string_variable_ containing all of the values of 1 to 255 as single characters and 0, (zero), as a two byte character set of \0.
The real binary files are 512 bytes in size and contains 2 zeros.
The _string_variable_ is 514 bytes in size and contains \0 for the byte value zero.
Ignore the simplicity of the for loops to generate the binary files it is the 'text' variable that is ultimately important.
I am not sure if it is of any use but shows that the bash shell can cope with binary...
Here is the display on a Macbook Pro 13" OSX 10.7.5 using the default Terminal.
I appreciate that the _string_ is not an actual character zero, but the original code replaces character zero with two characters - "\0".
I am on holiday/vacation ATM so gimme a bit of time to INPUT to a variable with the two pseudo-zero characters for an actual character zero and 0xFF as a single byte, a total of three characters...
If I get stuck I will certainly admit it... ;o)
---------- Post updated 21-08-13 at 09:52 AM ---------- Previous update was 20-08-13 at 10:29 PM ----------
Slightly bigger than 3 bytes... ;o)
This generates a variable "text" 10 bytes long containing three "\0" pseudo-zeros and other non-ascii characters. The binary file generated is either 7 or 10 bytes in size......
This is the best workaround I can do WRT to byte value zero and reading from the keyboard.
Reading the bash man page, 'read -n 1' looks like a nice start. I am not sure what happens when you read a line feed or white space, so I guess I have to try it. I wrote all256 to put out bytes 0x00 through 0xff.
Looks like $IFS characters and null become the empty string ''. The -e does not seem to change things. EOF is still handled the same.
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)