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.

yes<br />

banner<br />

printenv<br />

lp<br />

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

Il comportamento predefinito del comando yes è quello <strong>di</strong> inviare allo stdout una stringa continua<br />

del carattere y seguito da un ritorno a capo. Control-c termina l’esecuzione. Può essere specificata<br />

una <strong>di</strong>versa stringa <strong>di</strong> output, come yes altra stringa che visualizzerà in continuazione<br />

altra stringa allo stdout. Ci si può chiedere lo scopo <strong>di</strong> tutto questo. Sia da riga <strong>di</strong> comando<br />

che in uno script, l’output <strong>di</strong> yes può essere re<strong>di</strong>retto, o collegato per mezzo <strong>di</strong> una pipe, ad un<br />

programma in attesa <strong>di</strong> un input dell’utente. In effetti, <strong>di</strong>venta una specie <strong>di</strong> versione povera <strong>di</strong><br />

expect<br />

yes | fsck /dev/hda1 esegue fsck in modalità non-interattiva (attenzione!).<br />

yes | rm -r nome<strong>di</strong>r ha lo stesso effetto <strong>di</strong> rm -rf nome<strong>di</strong>r (attenzione!).<br />

Attenzione<br />

Si faccia soprattutto attenzione quando si collega, con una pipe, yes ad<br />

un comando <strong>di</strong> sistema potenzialmente pericoloso come fsck o f<strong>di</strong>sk.<br />

Potrebbero esserci degli effetti collaterali imprevisti.<br />

Visualizza gli argomenti allo stdout in forma <strong>di</strong> un ampio banner verticale, utilizzando un<br />

carattere ASCII (<strong>di</strong> default ’#’), che può essere re<strong>di</strong>retto alla stampante per un hardcopy.<br />

Visualizza tutte le variabili d’ambiente <strong>di</strong> un particolare utente.<br />

bash$ printenv | grep HOME<br />

HOME=/home/bozo<br />

I coman<strong>di</strong> lp ed lpr inviano uno o più file alla coda <strong>di</strong> stampa per l’hardcopy. 10 I nomi <strong>di</strong> questi<br />

coman<strong>di</strong> derivano da “line printer”, stampanti <strong>di</strong> un’altra epoca.<br />

bash$ lp file1.txt o bash lp

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

Saved successfully!

Ooh no, something went wrong!