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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>di</strong>alog<br />

sox<br />

Note<br />

1.<br />

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

accordo col nome con cui l’eseguibile è stato posto in esecuzione. Quello che si ottiene è un metodo<br />

in<strong>di</strong>retto per passare delle opzioni ad un eseguibile.<br />

Per esempio, la <strong>di</strong>rectory /usr/local/bin potrebbe contenere un binario <strong>di</strong> nome “aaa”.<br />

Eseguendo doexec /usr/local/bin/aaa list verrebbero elencati tutti quei file della <strong>di</strong>rectory <strong>di</strong> lavoro<br />

corrente che iniziano con una “a”, mentre (lo stesso eseguibile) con doexec /usr/local/bin/aaa<br />

delete quei file verrebbero cancellati.<br />

Nota: I <strong>di</strong>versi comportamenti dell’eseguibile devono essere definiti nel co<strong>di</strong>ce dell’eseguibile<br />

stesso, qualcosa <strong>di</strong> analogo al seguente script <strong>di</strong> shell:<br />

case ‘basename $0‘ in<br />

"nome1" ) fa_qualcosa;;<br />

"nome2" ) fa_qualcos_altro;;<br />

"nome3" ) fa_un_altra_cosa_ancora;;<br />

* ) azione_predefinita;;<br />

esac<br />

La famiglia <strong>di</strong> strumenti <strong>di</strong>alog fornisce un mezzo per richiamare, da uno script, box <strong>di</strong> “<strong>di</strong>alogo”<br />

interattivi. Le varianti più elaborate <strong>di</strong> <strong>di</strong>alog -- g<strong>di</strong>alog, X<strong>di</strong>alog e k<strong>di</strong>alog -- in realtà invocano i<br />

widget X-Windows. Ve<strong>di</strong> Esempio 33-19.<br />

Il comando sox, ovvero “sound exchange”, permette <strong>di</strong> ascoltare i file au<strong>di</strong>o e anche <strong>di</strong> mo<strong>di</strong>ficarne<br />

il formato. Infatti l’eseguibile /usr/bin/play (ora deprecato) non è nient’altro che uno shell<br />

wrapper per sox<br />

Per esempio, sox fileau<strong>di</strong>o.wav fileau<strong>di</strong>o.au trasforma un file musicale dal formato WAV al<br />

formato AU (au<strong>di</strong>o Sun).<br />

Gli script <strong>di</strong> shell sono l’ideale per eseguire in modalità batch operazioni sox sui file au<strong>di</strong>o. Per<br />

alcuni esempi, ve<strong>di</strong> il Linux Ra<strong>di</strong>o Timeshift HOWTO (http://osl.iu.edu/~tveldhui/ra<strong>di</strong>o/) e<br />

l’MP3do Project (http://savannah.nongnu.org/projects/au<strong>di</strong>odo).<br />

Vengono chiamati dotfiles quelli i cui nomi incominciano con un punto (dot), come ~/.Xdefaults, e che non<br />

vengono visualizzati con un semplice ls (sebbene ls -a ci riesca). Non possono neanche essere cancellati<br />

accidentalmente con un rm -rf *. I dotfile vengono solitamente usati come file <strong>di</strong> impostazione e configurazione<br />

nella <strong>di</strong>rectory home dell’utente.<br />

340

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

Saved successfully!

Ooh no, something went wrong!