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 17. Here document<br />

# Bram Moolenaar fa rilevare che questo potrebbe non funzionare con ’vim’,<br />

#+ a causa <strong>di</strong> possibili problemi <strong>di</strong> interazione con il terminale.<br />

exit 0<br />

Lo script precedente si potrebbe, semplicemente ed efficacemente, implementare con ex, invece che con<br />

vi. Gli here document che contengono una lista <strong>di</strong> coman<strong>di</strong> ex sono abbastanza comuni e formano una<br />

specifica categoria a parte, conosciuta come ex script.<br />

#!/bin/bash<br />

# Sostituisce tutte le occorrenze d "Smith" con "Jones"<br />

#+ nei file i cui nomi abbiano il suffisso ".txt".<br />

ORIGINALE=Smith<br />

SOSTITUTO=Jones<br />

for parola in $(fgrep -l $ORIGINALE *.txt)<br />

do<br />

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

$parola

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

Saved successfully!

Ooh no, something went wrong!