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.

echo<br />

# |----|<br />

# ---------------------------------------------------------<br />

# La verifica deve avvenire all’inizio/fine della stringa,<br />

#+ altrimenti non verrà eseguita alcuna sostituzione.<br />

# --------------------------------------------------------v3=${v0/#123/000}<br />

# È verificata, ma non all’inizio.<br />

echo "v3 = $v3" # abc1234zip1234abc<br />

# NESSUNA SOSTITUZIONE.<br />

v4=${v0/%123/000} # È stata verificata, ma non alla fine.<br />

echo "v4 = $v4" # abc1234zip1234abc<br />

# NESSUNA SOSTITUZIONE.<br />

exit 0<br />

${!prefissovar*}<br />

${!prefissovar@}<br />

Capitolo 9. Variabili riviste<br />

Verifica tutte le variabili precedentemente <strong>di</strong>chiarate i cui nomi iniziano con prefissovar.<br />

xyz23=qualsiasi_cosa<br />

xyz24=<br />

a=${!xyz*} # Espande i nomi delle variabili <strong>di</strong>chiarate che iniziano<br />

#+ con "xyz".<br />

echo "a = $a" # a = xyz23 xyz24<br />

a=${!xyz@} # Come prima.<br />

echo "a = $a" # a = xyz23 xyz24<br />

# La versione 2.04 <strong>di</strong> <strong>Bash</strong> possiede questa funzionalità.<br />

9.4. Tipizzare le variabili: declare o typeset<br />

I builtin declare o typeset (sono sinonimi esatti) consentono <strong>di</strong> limitare le proprietà delle variabili. È una<br />

forma molto debole <strong>di</strong> tipizzazione, se confrontata con quella <strong>di</strong>sponibile per taluni linguaggi <strong>di</strong><br />

programmazione. Il comando declare è specifico della versione 2 o successive <strong>di</strong> <strong>Bash</strong>. Il comando<br />

typeset funziona anche negli script ksh.<br />

opzioni declare/typeset<br />

-r readonly (sola lettura)<br />

declare -r var1<br />

138

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

Saved successfully!

Ooh no, something went wrong!