31.05.2013 Views

Comandi Bash shell - SisInf Lab

Comandi Bash shell - SisInf Lab

Comandi Bash shell - SisInf Lab

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.

CORSO DI FONDAMENTI DEI SISTEMI OPERATIVI<br />

A.A. 2012-2013<br />

(Prof. G. Piscitelli)<br />

Canali di comunicazione e ridirezione<br />

I programmi dispongono di 3 canali di comunicazione standard (standard file descriptor):<br />

0 Standard input (tastiera)<br />

1 Standard output (terminale)<br />

2 Standard error (terminale)<br />

La <strong>shell</strong> consente il reindirizzamento dei 3 canali standard all'interno di file con la sintassi:<br />

$ comando operatore file<br />

Operatori di ridirezione dello standard output<br />

Ridirige lo std output del comando sul file. Se il file non esiste, viene creato; se il file esiste, viene sovrascritto<br />

(>) oppure il nuovo output viene accodato (>>).<br />

SINTASSI: $ comando > file<br />

> ridirige lo standard output in modalità truncate<br />

SINTASSI: $ comando >> file<br />

>> ridirige lo standard output in modalità append<br />

$ who<br />

$ who > whofile<br />

$ cat whofile<br />

$ ls -l > stdout.txt<br />

$ cat stdout.txt<br />

$ echo parola esempio >> file_prova<br />

$ cat file1 file2 > file3<br />

Operatori di ridirezione dello standard error<br />

Ridirige lo std error del comando su file. Se il file non esiste, viene creato; se il file esiste, viene sovrascritto (2>)<br />

oppure il nuovo output viene accodato (2>>).<br />

SINTASSI: $ comando 2> file<br />

2> ridirige lo standard error in modalita truncate<br />

SINTASSI: $ comando 2>> file<br />

2>> ridirige lo standard error in modalità append<br />

Operatori di ridirezione dello standard input<br />

Ridirige lo std input del comando su file, cioè fa sì che l'input di un comando provenga, anziché da tastiera, da<br />

un file.<br />

SINTASSI: $ comando < file<br />

< ridirige lo standard input<br />

$ grep 'ciao' /home/silvia/file<br />

$ grep 'ciao' < /home/silvia/file<br />

L'interprete standard di comandi (sh), permette di eseguire comandi letti da una stringa a riga di comando (-c),<br />

dallo standard input (-s) o da un file specificato.<br />

Esercitazioni comandi <strong>shell</strong> <strong>Bash</strong> (Ing. S. Giannini) Pagina 32

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

Saved successfully!

Ooh no, something went wrong!