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.

!<br />

}<br />

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

# ==> ’bc’ è l’utility <strong>di</strong> calcolo.<br />

case "$dec" in<br />

[0-9]*) ;; # numero ok<br />

*) continue;; # errore: ignora<br />

esac<br />

# Visualizza tutte le conversioni su un’unica riga.<br />

# ==> ’here document’ fornisce una lista <strong>di</strong> coman<strong>di</strong> a ’bc’.<br />

echo ‘bc + poiché in ogni caso, o si esce dal ciclo<br />

# ==>+ oppure lo script termina.<br />

# ==> (Grazie, Paulo Marcel Coelho Aragao.)<br />

do<br />

case "$1" in<br />

--) shift; break;;<br />

-h) Utilizzo;; # ==> Messaggio <strong>di</strong> aiuto.<br />

-*) Utilizzo;;<br />

*) break;; # primo numero<br />

esac # ==> Sarebbe utile un’ulteriore verifica d’errore per un input<br />

#+ non consentito.<br />

shift<br />

done<br />

if [ $# -gt 0 ]<br />

then<br />

VisualizzaBasi "$@"<br />

else # legge dallo st<strong>di</strong>n<br />

while read riga<br />

do<br />

VisualizzaBasi $riga<br />

done<br />

fi<br />

exit 0<br />

Un metodo alternativo per invocare bc comprende l’uso <strong>di</strong> un here document inserito in un blocco<br />

<strong>di</strong> sostituzione <strong>di</strong> comando. Questo risulta particolarmente appropriato quando uno script ha la<br />

necessità <strong>di</strong> passare un elenco <strong>di</strong> opzioni e coman<strong>di</strong> a bc.<br />

319

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

Saved successfully!

Ooh no, something went wrong!