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.

false<br />

type [comando]<br />

Capitolo 11. Coman<strong>di</strong> interni e builtin<br />

# Ciclo infinito<br />

while true # alternativa a ":"<br />

do<br />

operazione-1<br />

operazione-2<br />

...<br />

operazione-n<br />

# Occorre un sistema per uscire dal ciclo, altrimenti lo script si blocca.<br />

done<br />

Comando che restituisce l’exit status <strong>di</strong> una esecuzione non andata a buon fine, ma nient’altro.<br />

Prova <strong>di</strong> "false"<br />

if false<br />

then<br />

echo "false valuta \"vero\""<br />

else<br />

echo "false valuta \"falso\""<br />

fi<br />

# false valuta "falso"<br />

# Ciclo while "falso" (ciclo nullo)<br />

while false<br />

do<br />

# Il co<strong>di</strong>ce seguente non verrà eseguito.<br />

operazione-1<br />

operazione-2<br />

...<br />

operazione-n<br />

# Non succede niente!<br />

done<br />

Simile al comando esterno which, type comando fornisce il percorso completo <strong>di</strong> “comando”. A<br />

<strong>di</strong>fferenza <strong>di</strong> which, type è un builtin <strong>di</strong> <strong>Bash</strong>. L’utile opzione -a <strong>di</strong> type identifica le parole<br />

chiave ed i builtin, in<strong>di</strong>viduando anche i coman<strong>di</strong> <strong>di</strong> sistema che hanno gli stessi nomi.<br />

bash$ type ’[’<br />

[ is a shell builtin<br />

bash$ type -a ’[’<br />

[ is a shell builtin<br />

[ is /usr/bin/[<br />

217

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

Saved successfully!

Ooh no, something went wrong!