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.

Capitolo 25. Costrutti lista<br />

# If they want to run something in single user mode, might as well run it...<br />

for i in /etc/rc1.d/S[0-9][0-9]* ; do<br />

# Check if the script is there.<br />

[ -x "$i" ] || continue<br />

# ==> Se il corrispondente file in $PWD *non* viene trovato,<br />

#+==> allora "continua" saltando all’inizio del ciclo.<br />

# Reject backup files and files generated by rpm.<br />

case "$1" in<br />

*.rpmsave|*.rpmorig|*.rpmnew|*~|*.orig)<br />

continue;;<br />

esac<br />

[ "$i" = "/etc/rc1.d/S00single" ] && continue<br />

# ==> Imposta il nome dello script, ma non lo esegue ancora.<br />

$i start<br />

done<br />

# ==> . . .<br />

Importante: L’exit status <strong>di</strong> una lista and o <strong>di</strong> una lista or corrisponde all’exit status<br />

dell’ultimo comando eseguito.<br />

Sono possibili ingegnose combinazioni <strong>di</strong> liste “and” e “or” , ma la loro logica potrebbe facilmente<br />

<strong>di</strong>ventare aggrovigliata e richiedere un debugging approfon<strong>di</strong>to.<br />

false && true || echo false # false<br />

# Stesso risultato <strong>di</strong><br />

( false && true ) || echo false # false<br />

# Ma *non*<br />

false && ( true || echo false ) # (non viene visualizzato niente)<br />

# Notate i raggruppamenti e la valutazione degli enunciati da sinistra a destra<br />

#+ perché gli operatori logici "&&" e "||" hanno la stessa priorità.<br />

# È meglio evitare tali complessità, a meno che non sappiate cosa state facendo<br />

# Grazie, S.C.<br />

Ve<strong>di</strong> Esempio A-7 e Esempio 7-4 per un’illustrazione dell’uso <strong>di</strong> una lista and / or per la<br />

verifica <strong>di</strong> variabili.<br />

471

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

Saved successfully!

Ooh no, something went wrong!