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.

elif<br />

exit 0<br />

Esercizio. Si spieghi il comportamento del precedente Esempio 7-1.<br />

Capitolo 7. Verifiche<br />

if [ con<strong>di</strong>zione-vera ]<br />

then<br />

comando 1<br />

comando 2<br />

...<br />

else<br />

# Opzionale (può anche essere omesso).<br />

# Aggiunge un determinato blocco <strong>di</strong> co<strong>di</strong>ce che verrà eseguito se la<br />

#+ con<strong>di</strong>zione <strong>di</strong> verifica è falsa.<br />

comando 3<br />

comando 4<br />

...<br />

fi<br />

Nota: Quando if e then sono sulla stessa riga occorre mettere un punto e virgola dopo l’enunciato if<br />

per in<strong>di</strong>carne il termine. Sia if che then sono parole chiave. Le parole chiave (o i coman<strong>di</strong>) iniziano<br />

gli enunciati e prima che un nuovo enunciato possa incominciare, sulla stessa riga, è necessario che<br />

il precedente venga terminato.<br />

if [ -x "$nome_file" ]; then<br />

Else if ed elif<br />

elif è la contrazione <strong>di</strong> else if. Lo scopo è quello <strong>di</strong> annidare un costrutto if/then in un altro.<br />

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

then<br />

comando1<br />

comando2<br />

comando3<br />

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

# Uguale a else if<br />

then<br />

comando4<br />

comando5<br />

else<br />

comando-predefinito<br />

66

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

Saved successfully!

Ooh no, something went wrong!