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.

Note<br />

Capitolo 32. Stile dello <strong>scripting</strong><br />

-s Impostazioni (setup) & Gestione File: file <strong>di</strong> configurazione<br />

dello script.<br />

-u Utilizzo: elenco delle opzioni d’esecuzione dello script.<br />

-v Dettaglio (verbose): informazioni dettagliate, più o meno formattate.<br />

-V Versione / Licenza / Copy(right|left) / Contributi (anche email).<br />

Ve<strong>di</strong> anche Appen<strong>di</strong>ce F.<br />

• Si sud<strong>di</strong>vidano gli script complessi in moduli più semplici. Si faccia uso delle funzioni ogni qual volta<br />

se ne presenti l’occasione. Ve<strong>di</strong> Esempio 34-4.<br />

• Non si usi un costrutto complesso dove uno più semplice è sufficiente.<br />

COMANDO if [ $? -eq 0 ]<br />

...<br />

# Ridondante e non intuitivo.<br />

if COMANDO<br />

...<br />

# Più conciso (anche se, forse, non altrettanto leggibile).<br />

... rea<strong>di</strong>ng the UNIX source code to the<br />

Bourne shell (/bin/sh). I was shocked at<br />

how much simple algorithms could be<br />

made cryptic, and therefore useless, by a<br />

poor choice of code style. I asked<br />

myself, “Could someone be proud of this<br />

code?”<br />

Landon Noll<br />

1. In questo contesto, il termine “magic number” ha un significato completamente <strong>di</strong>verso dal magic<br />

number usato per designare i tipi <strong>di</strong> file.<br />

544

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

Saved successfully!

Ooh no, something went wrong!