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.

# Re<strong>di</strong>rige lo stderr nel file "nomefile".<br />

2>>nomefile<br />

# Re<strong>di</strong>rige e accoda lo stderr nel file "nomefile".<br />

&>nomefile<br />

# Re<strong>di</strong>rige sia lo stdout che lo stderr nel file "nomefile".<br />

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

#=====================================================================<br />

# Re<strong>di</strong>rigere lo stdout una riga alla volta.<br />

FILELOG=script.log<br />

echo "Questo enunciato viene inviato al file <strong>di</strong> log, \<br />

\"$FILELOG\"." 1>$FILELOG<br />

echo "Questo enunciato viene accodato in \"$FILELOG\"." 1>>$FILELOG<br />

echo "Anche questo enunciato viene accodato in \"$FILELOG\"." 1>>$FILELOG<br />

echo "Questo enunciato viene visualizzato allo \<br />

stdout e non comparirà in \"$FILELOG\"."<br />

# Questi coman<strong>di</strong> <strong>di</strong> re<strong>di</strong>rezione vengono automaticamente "annullati"<br />

#+ dopo ogni riga.<br />

# Re<strong>di</strong>rigere lo stderr una riga alla volta.<br />

FILEERRORI=script.err<br />

comando_errato1 2>$FILEERRORI # Il messaggio d’errore viene<br />

#+ inviato in $FILEERRORI.<br />

comando_errato2 2>>$FILEERRORI # Il messaggio d’errore viene<br />

#+ accodato in $FILEERRORI.<br />

comando_errato3 # Il messaggio d’errore viene<br />

#+ visualizzato allo stderr,<br />

#+ e non comparirà in $FILEERRORI.<br />

# Questi coman<strong>di</strong> <strong>di</strong> re<strong>di</strong>rezione vengono automaticamente "annullati"<br />

#+ dopo ogni riga.<br />

#=====================================================================<br />

2>&1<br />

# Re<strong>di</strong>rige lo stderr allo stdout.<br />

# I messaggi d’errore vengono visualizzati a video, ma come stdout.<br />

i>&j<br />

# Re<strong>di</strong>rige il descrittore <strong>di</strong> file i in j.<br />

# Tutti gli output del file puntato da i vengono inviati al file<br />

#+ puntato da j.<br />

>&j<br />

# Re<strong>di</strong>rige, per default, il descrittore <strong>di</strong> file 1 (lo stdout) in j.<br />

# Tutti gli stdout vengono inviati al file puntato da j.<br />

0< NOMEFILE<br />

< NOMEFILE<br />

# Riceve l’input da un file.<br />

395

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

Saved successfully!

Ooh no, something went wrong!