11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

echo "Dato il capitale, il tasso d’interesse e la durata del mutuo,"<br />

echo "calcola la rata <strong>di</strong> rimborso mensile."<br />

denominatore=1.0<br />

echo<br />

echo -n "Inserisci il capitale (senza i punti <strong>di</strong> separazione)"<br />

read capitale<br />

echo -n "Inserisci il tasso d’interesse (percentuale)" # Se 12% inserisci "12",<br />

#+ non ".12".<br />

read t_interesse<br />

echo -n "Inserisci la durata (mesi)"<br />

read durata<br />

t_interesse=$(echo "scale=9; $t_interesse/100.0" | bc) # Lo converte<br />

#+ in decimale.<br />

# "scale" determina il numero delle cifre decimali.<br />

tasso_interesse=$(echo "scale=9; $t_interesse/12 + 1.0" | bc)<br />

numeratore=$(echo "scale=9; $capitale*$tasso_interesse^$durata" | bc)<br />

echo; echo "Siate pazienti. È necessario un po’ <strong>di</strong> tempo."<br />

let "mesi = $durata - 1"<br />

# ====================================================================<br />

for ((x=$mesi; x > 0; x--))<br />

do<br />

den=$(echo "scale=9; $tasso_interesse^$x" | bc)<br />

denominatore=$(echo "scale=9; $denominatore+$den" | bc)<br />

# denominatore = $(($denominatore + $den"))<br />

done<br />

# ====================================================================<br />

# --------------------------------------------------------------------<br />

# Rick Boivie ha in<strong>di</strong>cato un’implementazione più efficiente del<br />

#+ ciclo precedente che riduce <strong>di</strong> 2/3 il tempo <strong>di</strong> calcolo.<br />

# for ((x=1; x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!