want play with binary data in a shell script and
don't know how to do this
real world problem of course more complex,
but this code what I want to have:
#!/bin/bash
#works with this:
#echo -n "2" > /tmp/foo
#but does not work with hex value
echo -n $'\x61' > /tmp/foo
FOO="`cat /tmp/foo`"
echo "FOO is: $FOO"
#(in reality more calculation)
FOO=$(($FOO+3))
echo "now FOO is: $FOO"
#write back as hex file
echo -n $FOO > /tmp/foo2
- read from binary file which is 1 byte long
- do some calculation ...
- write back to another binary file, also 1 byte long
- unfortunately this code does not work
with hex value (any value 0x00 .. 0xFE must work)
note: must run on an embedded device,
I do NOT have bc, dc, perl, python, od, awk ...
available is:
bash (incl. printf), sed, grep, tr ..
any ideas are appreciated
Thank you,
Frank
¿Perhaps you want this?
$ echo -n 61 > /tmp/foo
$ FOO="`cat /tmp/foo`"
$ echo $(( 16#$FOO )) ## echoes decimal
97
$ echo $(( 16#$FOO + 3 ))
100
$ printf "%x" $(( 16#$FOO + 3 )) ## back to hex
64
--
David Serrano
:; cLIeNUX /dev/tty4 03:43:14 /
:;echo $((15#aabb))
36176
:; cLIeNUX /dev/tty4 03:54:54 /
:;echo $((15#aabc))
36177
:; cLIeNUX /dev/tty4 03:54:58 /
:;echo $((2#0000111000))
56
Wow. I wrote an assembler in Bash without knowing that.
Approximately when did Bash get that, ya think? And how widespread is it?
--
Rick (Richard Allen) Hohensee
write-in candidate, President of the United States of America
platform ftp://linux01.gwdg.de/pub/cLIeNUX/interim/platform2
personal webpage http://linux01.gwdg.de/~rhohen
active in Usenet alt.politics colorg on IRC
humb...@smart.net Maryland, USA
Ground troops out of Iraq Put the CIA under INS Save Darfur
Semi-legalize drugs Prosecute Bush Tighten the borders
Isolate Israel Tax churches halve military aquisitions
government jobs for Iraq-wounded soldiers and 9-11 survivors
please email my platform to friends, blogs and countrymen
-------------------------------------------------------------
<snip>
>
> --
>
> Rick (Richard Allen) Hohensee
> write-in candidate, President of the United States of America
> platform ftp://linux01.gwdg.de/pub/cLIeNUX/interim/platform2
> personal webpage http://linux01.gwdg.de/~rhohen
> active in Usenet alt.politics colorg on IRC
> humb...@smart.net Maryland, USA
> Ground troops out of Iraq Put the CIA under INS Save Darfur
> Semi-legalize drugs Prosecute Bush Tighten the borders
> Isolate Israel Tax churches halve military aquisitions
> government jobs for Iraq-wounded soldiers and 9-11 survivors
> please email my platform to friends, blogs and countrymen
> -------------------------------------------------------------
>
Just what we need for a President: Someone who ignores the
rules. Someone who thinks they are better than everyone else
and don't have to live by the rules that the rest of us live
by.
Like the Netiquette guidelines limiting signatures to 4 lines.
Which you have been informed of on previous occassions and
still persist in ignoring.
Not to mention the fact that you ignore the examples set by
almost everyone else on the Usenet.
You weren't elected because Americans don't elect arrogant
upstarts who have no respect for the rules.
People should know that any clueless jerk can become a
write-in canditate for President.
And most of them, like you, don't get a single vote.
I see that you want to prosecute Bush for his violations,
but don't seem to even be aware of your own, even when
someone spells it out for you.
Thanks. Bush may be a drag, but you are certainly no better.
I wouldn't put you in charge of my garbage pail.
I wouldn't let you in my house.
No doubt, you can rationalize thievery without any problem
too.
AC
Here is a hexdump program I wrote in bash. Maybe it will help you
figure out how to do what you want to do, since it sounds very
similar. It reads from stdin:
#!/bin/bash
digs="0 1 2 3 4 5 6 7 8 9 A B C D E F"
c=0
next=0
while IFS="" read -d "" -rn 1 char; do
for i in $digs; do
for j in $digs; do
if eval [ \""\$char"\" = \$\'\\x$i$j\' ]; then
echo -n "$i$j "
[ $c -eq 7 ] && echo -n " "
[ $c -eq 15 ] && echo -ne "\n"
next=1
break
fi
done
[ $next = "1" ] && break
done
next=0
if [ $c -eq 15 ]; then c=0; else c=$[$c + 1]; fi
done
echo
--
*** SPAM BLOCK: Remove bra before replying! ***
http://runslinux.net :: moshe at runslinux dot net :: AIM: Jehsom
> <snip>
>>
>> --
>>
>> Rick (Richard Allen) Hohensee
>> write-in candidate, President of the United States of America
>> platform ftp://linux01.gwdg.de/pub/cLIeNUX/interim/platform2
>> personal webpage http://linux01.gwdg.de/~rhohen
>> active in Usenet alt.politics colorg on IRC
>> humb...@smart.net Maryland, USA
>> Ground troops out of Iraq Put the CIA under INS Save Darfur
>> Semi-legalize drugs Prosecute Bush Tighten the borders
>> Isolate Israel Tax churches halve military aquisitions
>> government jobs for Iraq-wounded soldiers and 9-11 survivors
>> please email my platform to friends, blogs and countrymen
>> -------------------------------------------------------------
>>
> Just what we need for a President: Someone who ignores the
> rules. Someone who thinks they are better than everyone else
> and don't have to live by the rules that the rest of us live
> by.
Hmmm, most odd, this one...
How did you see this post, mr connor? After all, you use a script that
deletes posts that "break the rules" (what rules would they be again?).
No, scratch that, it doesn't delete the posts, it just deletes the BODY of
the post, so as not to offend thine eye, while at the same time allowing you
to complain about it.
> Like the Netiquette guidelines limiting signatures to 4 lines.
Guideline from 20 years ago when modems were crap and disk space exceedingly
limited != "rule".
> Which you have been informed of on previous occassions and
> still persist in ignoring.
As he should. Who made you lord sherrif of usenet anyway?
> Not to mention the fact that you ignore the examples set by
> almost everyone else on the Usenet.
Wooooo, big deal, his signature is 9 (shock horror) lines above your decreed
maximum. what is that?
768 bytes in total? shock horror.
> I see that you want to prosecute Bush for his violations,
His violations cost lives. He lied to get the war he wanted just to finished
daddy's work. 768 bytes of plain text never hurt anyone. (well, not
physically, I suppose 768 bytes of plain text is enough to wreck someone's
career or reputation...)
> Thanks. Bush may be a drag, but you are certainly no better.
LOL! I'd argumentificate to denify that examplitude.
<snip>
"spike"
I checked out your posting history (under _this_ alias) at
http://groups.google.com/advanced_group_search
You are one of these losers that just wanders all over the
Usenet running your ignorant mouth.
Never seen anyone who posted on such a wide variety of
groups.
But then, I'm sure they get tired of you really quick.
Not interested in what you have to say.
Run along.
AC
> "Alan Connor" wrote:
>
> <snip>
>
>
> "spike"
>
> I checked out your posting history (under _this_ alias) at
>
> http://groups.google.com/advanced_group_search
>
> You are one of these losers that just wanders all over the
> Usenet running your ignorant mouth.
Nah, that would be you.
>
> Never seen anyone who posted on such a wide variety of
> groups.
Hardly a crime, and equally, none of your business, I reckon.
>
> But then, I'm sure they get tired of you really quick.
Not as quickly as people get tired of you.
>
> Not interested in what you have to say.
Why do you suppose anyone is interested in what You have to say? You're
pretty well known yourself, as a tedious idiot.
>
> Run along.
Yes, please do.
--
Kier
> <snip>
> "spike"
> I checked out your posting history (under _this_ alias) at
> http://groups.google.com/advanced_group_search
Oh that's clever of you... I'd've never thought of that myself...
> You are one of these losers that just wanders all over the
> Usenet running your ignorant mouth.
"all over usenet"... "ignorant mouth"
LOL! I'd hardly call a selection of 10 newsgroups "all over usenet"
And exactly what is my mouth "ignorant" of?
> Never seen anyone who posted on such a wide variety of
> groups.
Wide variety?
I'd hardly call a 4 linux groups, 2 stargate groups, a sinclair group, a
reboot group and a couple of others "wide variety".
So, you only ever had any interest in one subject ever, did you?
You never thought "I *LOVED* THAT EPISODE OF xxxxxx!" and wanted to talk
about it? You never had any interest in, say, retro computers or gardening
or sport and thought, ooo, usenet, there's an idea!
Or... oh *I* know... you're too DUMB to spot a crosspost when you see one.
Which is ironic when you consider this thing's crossposted all over the
linux groups, BY YOU.
> Not interested in what you have to say.
you never were, in our first encounter you proved that.
You're a loudmouth and a troll, connor, you always get a bee in your bonnet
about insignificant things like "ooo, his sig's 3 lines too long! BURN HIM!
BURN HIM!". It's time you grew up.
> Run along.
Nope, I'm not goin anywhere.
Not to mention that it is, very likely, protected political speech.
Now look, it's obvious from his sig that this guy is an absolute
loon, but it is his right to make that clear to as many people as
he can. Stopping him might turn out to be a dis-service to the
country and the world
--
Pete LaGrange
loyalty above all, save honor
> You are one of these losers that just wanders all over the
> Usenet running your ignorant mouth.
Losers? Ignorant mouth? Are you this Alan Connor?
http://angel.1jh.com/nanae/kooks/alanconnor.shtml
> Not interested in what you have to say.
People are interested in what you have to say, Alan. They collect
your ravings and say this about you:
"Alan Connor appears to be deliberately setting out to attain,
one by one, the several distinct qualifications for kookhood."
>> You are one of these losers that just wanders all over the
>> Usenet running your ignorant mouth.
> Losers? Ignorant mouth? Are you this Alan Connor?
> http://angel.1jh.com/nanae/kooks/alanconnor.shtml
Ahhh yes, read most of that (and most of the links) a few months ago..
Loved the bit with him walking through the woods intent on murder and
running into a community of tolkien elves who show him the error of his
ways.
:)
That might be how he posts to usenet...
They must have a palantir there.
:)
Not the first time for such churlish behavior.
Judicious use of the killfile here results in _zero_ lines.