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.

È possibile eseguire processi in parallelo per mezzo <strong>di</strong> <strong>di</strong>fferenti subshell. Questo permette <strong>di</strong><br />

sud<strong>di</strong>videre un compito complesso in sottocomponenti elaborate contemporaneamente.<br />

Esempio 20-3. Eseguire processi paralleli tramite le subshell<br />

Capitolo 20. Subshell<br />

(cat lista1 lista2 lista3 | sort | uniq > lista123) &<br />

(cat lista4 lista5 lista6 | sort | uniq > lista456) &<br />

# Unisce ed or<strong>di</strong>na entrambe le serie <strong>di</strong> liste simultaneamente.<br />

# L’esecuzione in background assicura l’esecuzione parallela.<br />

#<br />

# Stesso effetto <strong>di</strong><br />

# cat lista1 lista2 lista3 | sort | uniq > lista123 &<br />

# cat lista4 lista5 lista6 | sort | uniq > lista456 &<br />

wait # Il comando successivo non viene eseguito finché le subshell<br />

#+ non sono terminate.<br />

<strong>di</strong>ff lista123 lista456<br />

Per la re<strong>di</strong>rezione I/O a una subshell si utilizza l’operatore <strong>di</strong> pipe “|”, come in ls -al |<br />

(comando).<br />

Nota: Un elenco <strong>di</strong> coman<strong>di</strong> tra parentesi graffe non esegue una subshell.<br />

{ comando1; comando2; comando3; ... }<br />

437

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

Saved successfully!

Ooh no, something went wrong!