[uae] Re: Very ugly hdfcreator in bash

  • From: Giulio Canevari <giuliogiuseppe.canevari01@xxxxxxxxxxx>
  • To: uae@xxxxxxxxxxxxx
  • Date: Thu, 14 Jul 2005 20:33:13 +0200

elmar@xxxxxxxxxxxxxxxxxx wrote:

Hi Gingat!

Gingat Florent wrote:

[snip]
...
Sorry, maybe "quoted-printable" was the wrong choice for the attachment. I'll paste the script at the bottom of this mail.

Calculations in the shell are a bit tricky. The least common denominator seems to be the 'dc' command (desktop calculator?) which features some reverse polish
notations (like in forth or postscript ...).


Unfortunately dc expects a file which contains the appropriate commands. Now, the special file name '-' means standard input. So the following commands get piped into dc via the echo command
(in human readable form)

I reply only now cause i have had a bad hd failure ( a 6 month old 160 gb maxtor :( )


I think bc is standard enought and easier to be used, even if here it's enought a $(( a * b )) .

For example here is a piece of code from mod2ogg.sh included in uade ( unix amiga delitracker emulator, used to play mods from amiga on a linux pc ) i wrote and i'm mantaining:

STOPTIME=`echo "scale=4 ; $TMPFILESIZE / 176400" | bc`

In the script this should be

count= $( echo $2 * 2048 | bc )

imho clearer and easier than  "count=`echo $2 "2048  * p q" | dc -` "

in Fact echoing scale=4 mean 4 digits after the point, then i want to divide $TMPFILESIZE by 176400 in a normal fashion, without reverse polish madness.

Returning to the script, i would write:

count= $(( $2 * 2048 ))

And also this script seems posix compliant, so it's better to change /bin/bash to /bin/sh

Bye,
--
Giulio Canevari


Other related posts: