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 34. <strong>Bash</strong>, versioni 2 e 3<br />

34.1. <strong>Bash</strong>, versione 2<br />

La versione corrente <strong>di</strong> <strong>Bash</strong>, quella che viene eseguita sulla vostra macchina, attualmente è la 2.XX.Y o<br />

la 3.xx.y..<br />

bash$ echo $BASH_VERSION<br />

2.05.b.0(1)-release<br />

La versione 2, aggiornamento del classico linguaggio <strong>di</strong> <strong>scripting</strong> <strong>di</strong> <strong>Bash</strong>, ha aggiunto gli array, 1<br />

l’espansione <strong>di</strong> stringa e <strong>di</strong> parametro, e un metodo migliore per le referenziazioni in<strong>di</strong>rette a variabili.<br />

Esempio 34-1. Espansione <strong>di</strong> stringa<br />

#!/bin/bash<br />

# Espansione <strong>di</strong> stringa.<br />

# Introdotta con la versione 2 <strong>di</strong> <strong>Bash</strong>.<br />

# Le stringhe nella forma $’xxx’<br />

#+ consentono l’interpretazione delle sequenze <strong>di</strong> escape standard.<br />

echo $’Tre segnali acustici \a \a \a’<br />

# Su alcuni terminali potrebbe venir eseguito un solo segnale acustico.<br />

echo $’Tre form feed \f \f \f’<br />

echo $’10 ritorni a capo \n\n\n\n\n\n\n\n\n\n’<br />

echo $’\102\141\163\150’ # <strong>Bash</strong><br />

# Valori ottali <strong>di</strong> ciascun carattere.<br />

exit 0<br />

Esempio 34-2. Referenziazioni in<strong>di</strong>rette a variabili - una forma nuova<br />

#!/bin/bash<br />

# Referenziazione in<strong>di</strong>retta a variabile.<br />

# Possiede alcuni degli attributi delle referenziazioni del C++.<br />

a=lettera_alfabetica<br />

lettera_alfabetica=z<br />

echo "a = $a" # Referenziazione <strong>di</strong>retta.<br />

587

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

Saved successfully!

Ooh no, something went wrong!