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.

Nota a margineterminali e modalità<br />

Capitolo 13. Coman<strong>di</strong> <strong>di</strong> sistema e d’amministrazione<br />

Normalmente, un terminale lavora in modalità canonica. Questo significa che<br />

quando un utente preme un tasto il carattere corrispondente non viene inviato<br />

imme<strong>di</strong>atamente al programma in esecuzione in quel momento sul terminale.<br />

Tutti i tasti premuti vengono registrati in un buffer specifico per quel terminale.<br />

Solo quando l’utente preme il tasto INVIO i caratteri <strong>di</strong>gitati, che sono stati<br />

salvati nel buffer, vengono inviati al programma in esecuzione. All’interno <strong>di</strong><br />

ciascun terminale è anche presente un elementare e<strong>di</strong>tor <strong>di</strong> linea.<br />

bash$ stty -a<br />

speed 9600 baud; rows 36; columns 96; line = 0;<br />

intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = ; eol2 = ;<br />

start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O;<br />

...<br />

isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt<br />

Utilizzando la modalità canonica è possibile ridefinire i tasti speciali dell’e<strong>di</strong>tor <strong>di</strong><br />

riga del terminale.<br />

bash$ cat > filexxx<br />

whaIfoo barciao mondo<br />

<br />

bash$ cat filexxx<br />

ciao mondo<br />

bash$ wc -c < filexxx<br />

11<br />

Il processo che controlla il terminale riceve solamente 11 caratteri (10 alfabetici,<br />

più un ritorno a capo), sebbene l’utente abbia premuto 26 tasti.<br />

In modalità non-canonica (“raw” - grezza), la pressione <strong>di</strong> ciascun tasto (compresi<br />

gli abbinamenti speciali come ctl-H) determina l’invio imme<strong>di</strong>ato del<br />

corrispondente carattere al processo <strong>di</strong> controllo.<br />

Il prompt <strong>di</strong> <strong>Bash</strong> <strong>di</strong>sabilita sia icanon che echo, dal momento che sostituisce<br />

l’e<strong>di</strong>tor <strong>di</strong> riga del terminale con un suo e<strong>di</strong>tor più elaborato. Così, per esempio, se<br />

si <strong>di</strong>gita ctl-A al prompt della shell, non viene visualizza ^A sullo schermo, <strong>Bash</strong><br />

invece riceve il carattere \1, lo interpreta e sposta il cursore all’inizio della riga.<br />

Stéphane Chazelas<br />

350

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

Saved successfully!

Ooh no, something went wrong!