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.

-a<br />

-o<br />

Capitolo 7. Verifiche<br />

# In questo punto dello script "exit $?" è inutile perché lo script,<br />

# in ogni caso, restituirà l’exit status dell’ultimo comando eseguito.<br />

confronti composti<br />

and logico<br />

exp1 -a exp2 restituisce vero se entrambe exp1 e exp2 sono vere.<br />

or logico<br />

exp1 -o exp2 restituisce vero se è vera o exp1 o exp2.<br />

Sono simili agli operatori <strong>di</strong> confronto <strong>Bash</strong> && e || utilizzati all’interno delle doppie parentesi quadre.<br />

[[ con<strong>di</strong>zione1 && con<strong>di</strong>zione2 ]]<br />

Gli operatori -o e -a vengono utilizzati con il comando test o all’interno delle parentesi quadre singole.<br />

if [ "$exp1" -a "$exp2" ]<br />

Fate riferimento ad Esempio 8-3, Esempio 26-16 e Esempio A-28 per vedere all’opera gli operatori <strong>di</strong><br />

confronto composto.<br />

7.4. Costrutti con<strong>di</strong>zionali if/then annidati<br />

È possibile annidare i costrutti con<strong>di</strong>zionali if/then. Il risultato è lo stesso <strong>di</strong> quello ottenuto utilizzando<br />

l’operatore <strong>di</strong> confronto composto && visto precedentemente.<br />

if [ con<strong>di</strong>zione1 ]<br />

then<br />

if [ con<strong>di</strong>zione2 ]<br />

then<br />

fa-qualcosa # Ma solo se sia "con<strong>di</strong>zione1" che "con<strong>di</strong>zione2" sono vere.<br />

fi<br />

fi<br />

81

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

Saved successfully!

Ooh no, something went wrong!