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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

awk<br />

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

bash$ echo "16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D68736142snlbxq" | dc"<br />

<strong>Bash</strong><br />

Esempio 12-47. Fattorizzazione<br />

#!/bin/bash<br />

# factr.sh: Fattorizza un numero<br />

MIN=2 # Non funzionerà con con un numero inferiore a questo.<br />

E_ERR_ARG=65<br />

E_INFERIORE=66<br />

if [ -z $1 ]<br />

then<br />

echo "Utilizzo: $0 numero"<br />

exit $E_ERR_ARG<br />

fi<br />

if [ "$1" -lt "$MIN" ]<br />

then<br />

echo "Il numero da fattorizzare deve essere $MIN o maggiore."<br />

exit $E_INFERIORE<br />

fi<br />

# Esercizio: Aggiungete una verifica <strong>di</strong> tipo (per rifiutare un argomento<br />

#+ <strong>di</strong>verso da un intero).<br />

echo "Fattori primi <strong>di</strong> $1:"<br />

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

"$1[p]s2[lip/dli%0=1dvsr]s12sid2%0=13sidvsr[dli%0=1lrli2+dsi!>.]ds.xd1

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

Saved successfully!

Ooh no, something went wrong!