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.

-i intero<br />

-a array<br />

-f funzioni<br />

(declare -r var1 è uguale a readonly var1)<br />

Capitolo 9. Variabili riviste<br />

È approssimativamente equivalente al qualificatore <strong>di</strong> tipo const del C. Il tentativo <strong>di</strong> mo<strong>di</strong>ficare il<br />

valore <strong>di</strong> una variabile in sola lettura fallisce generando un messaggio d’errore.<br />

declare -i numero<br />

# Lo script tratterà le successive occorrenze <strong>di</strong> "numero" come un intero.<br />

numero=3<br />

echo "numero = $numero" # Numero = 3<br />

numero=tre<br />

echo "Numero = $numero" # numero = 0<br />

# Cerca <strong>di</strong> valutare la stringa "tre" come se fosse un intero.<br />

Sono consentire alcune operazioni aritmetiche sulle variabili <strong>di</strong>chiarate interi senza la necessità <strong>di</strong><br />

usare expr o let.<br />

n=6/3<br />

echo "n = $n" # n = 6/3<br />

declare -i n<br />

n=6/3<br />

echo "n = $n" # n = 2<br />

declare -a in<strong>di</strong>ci<br />

La variabile in<strong>di</strong>ci verrà trattata come un array.<br />

declare -f<br />

In uno script, una riga con declare -f senza alcun argomento, elenca tutte le funzioni<br />

precedentemente definite in quello script.<br />

139

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

Saved successfully!

Ooh no, something went wrong!