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.

Note<br />

echo "foo<br />

bar"<br />

#foo<br />

#bar<br />

echo<br />

echo ’foo<br />

bar’ # Ancora nessuna <strong>di</strong>fferenza.<br />

#foo<br />

#bar<br />

echo<br />

echo foo\<br />

bar # Eseguito l’escaping del carattere a capo.<br />

#foobar<br />

echo<br />

Capitolo 5. Quoting<br />

echo "foo\<br />

bar" # Stesso risultato, perché \ viene ancora interpretato come escape<br />

#+ quando è posto tra apici doppi.<br />

#foobar<br />

echo<br />

echo ’foo\<br />

bar’ # Il carattere <strong>di</strong> escape \ viene interpretato letteralmente a causa<br />

#+ del quoting forte.<br />

#foo\<br />

#bar<br />

# Esempi suggeriti da Stéphane Chazelas.<br />

1. A meno che non ci sia, nella <strong>di</strong>rectory <strong>di</strong> lavoro corrente, un file con nome prima. Una ragione in<br />

più per usare il quoting. (Grazie a Harald Koenig per averlo sottolineato.<br />

2. Si hanno effetti collaterali sul valore della variabile (ve<strong>di</strong> oltre)<br />

3. Racchiudere il “!” tra doppi apici provoca un errore se usato da riga <strong>di</strong> comando. Viene interpretato<br />

come un comando <strong>di</strong> cronologia. In uno script, tuttavia, questo problema non si presenta, dal<br />

momento che la cronologia dei coman<strong>di</strong> <strong>di</strong> <strong>Bash</strong> è <strong>di</strong>dabilitata.<br />

Più interessante è il comportamento incoerente della “\” quando si trova tra i doppi apici.<br />

57

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

Saved successfully!

Ooh no, something went wrong!