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.

Saluti dalla parte Perl dello script.<br />

33.3. Verifiche e confronti: alternative<br />

Capitolo 33. Miscellanea<br />

Per le verifiche è più appropriato il costrutto [[ ]] che non con [ ]. Lo stesso vale per il costrutto (( )) per<br />

quanto concerne i confronti aritmetici.<br />

a=8<br />

# Tutti i confronti seguenti si equivalgono.<br />

test "$a" -lt 16 && echo "sì, $a < 16" # "lista and"<br />

/bin/test "$a" -lt 16 && echo "sì, $a < 16"<br />

[ "$a" -lt 16 ] && echo "sì, $a < 16"<br />

[[ $a -lt 16 ]] && echo "sì, $a < 16" # Non è necessario il quoting<br />

#+ delle variabili presenti in [[ ]] e (( )).<br />

(( a < 16 )) && echo "sì, $a < 16"<br />

città="New York"<br />

# Anche qui, tutti i confronti seguenti si equivalgono.<br />

test "$città" \< Parigi && echo "Sì, Parigi è più grande <strong>di</strong> $città"<br />

# Più grande in or<strong>di</strong>ne ASCII.<br />

/bin/test "$città" \< Parigi && echo "Sì, Parigi è più grande <strong>di</strong> $città"<br />

[ "$città" \< Parigi ] && echo "Sì, Parigi è più grande <strong>di</strong> $città"<br />

[[ $città < Parigi ]] && echo "Sì, Parigi è più grande <strong>di</strong> $città"<br />

# $città senza quoting.<br />

# Grazie, S.C.<br />

33.4. Ricorsività<br />

Può uno script richiamare sé stesso ricorsivamente? Certo.<br />

Esempio 33-8. Un (inutile) script che richiama sé stesso ricorsivamente<br />

#!/bin/bash<br />

# recurse.sh<br />

# Può uno script richiamare sé stesso ricorsivamente?<br />

# Sì, ma può essere <strong>di</strong> qualche uso pratico?<br />

# (Ve<strong>di</strong> il successivo.)<br />

INTERVALLO=10<br />

VALMAX=9<br />

552

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

Saved successfully!

Ooh no, something went wrong!