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.

n&-<br />

# Nella re<strong>di</strong>rezione congiunta <strong>di</strong> stdout e stderr,<br />

#+ non è in<strong>di</strong>fferente l’or<strong>di</strong>ne dei coman<strong>di</strong>.<br />

Chiusura dei descrittori <strong>di</strong> file<br />

Chiude il descrittore del file <strong>di</strong> input n.<br />

Chiude lo st<strong>di</strong>n.<br />

Chiude il descrittore del file <strong>di</strong> output n.<br />

Chiude lo stdout.<br />

Capitolo 16. Re<strong>di</strong>rezione I/O<br />

I processi figli ere<strong>di</strong>tano dai processi genitore i descrittori dei file aperti. Questo è il motivo per cui le<br />

pipe funzionano. Per evitare che un descrittore <strong>di</strong> file venga ere<strong>di</strong>tato è necessario chiuderlo.<br />

# Re<strong>di</strong>rige solo lo stderr alla pipe.<br />

exec 3>&1 # Salva il "valore" corrente dello stdout.<br />

ls -l 2>&1 >&3 3>&- | grep bad 3>&- # Chiude il df 3 per ’grep’ (ma<br />

#+ non per’ls’).<br />

# ^^^^ ^^^^<br />

exec 3>&- # Ora è chiuso anche per la parte<br />

#+ restante dello script.<br />

# Grazie, S.C.<br />

Per una più dettagliata introduzione alla re<strong>di</strong>rezione I/O ve<strong>di</strong> Appen<strong>di</strong>ce E.<br />

16.1. Uso <strong>di</strong> exec<br />

Il comando exec

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

Saved successfully!

Ooh no, something went wrong!