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.

-<br />

then<br />

echo "$a è uguale a $b."<br />

fi<br />

if [ "$c" -eq 24 -a "$d" -eq 47 ]<br />

then<br />

echo "$c è uguale a 24 e $d è uguale a 47."<br />

fi<br />

re<strong>di</strong>rezione dallo/allo st<strong>di</strong>n o stdout [trattino].<br />

Capitolo 3. Caratteri speciali<br />

(cd /source/<strong>di</strong>rectory && tar cf - . ) | (cd /dest/<strong>di</strong>rectory && tar xpvf -)<br />

# Sposta l’intero contenuto <strong>di</strong> una <strong>di</strong>rectory in un’altra<br />

# [cortesia <strong>di</strong> Alan Cox , con una piccola mo<strong>di</strong>fica]<br />

# 1) cd /source/<strong>di</strong>rectory Directory sorgente, dove sono contenuti i file che<br />

# devono essere spostati.<br />

# 2) && "lista And": se l’operazione ’cd’ ha successo,<br />

# allora viene eseguito il comando successivo.<br />

# 3) tar cf - . L’opzione ’c’ del comando <strong>di</strong> archiviazione ’tar’<br />

# crea un nuovo archivio, l’opzione ’f’ (file),<br />

# seguita da ’-’ designa come file <strong>di</strong> destinazione<br />

# lo sdtout, e lo fa nella <strong>di</strong>rectory corrente (’.’).<br />

# 4) | Collegato a...<br />

# 5) ( ... ) subshell<br />

# 6) cd /dest/<strong>di</strong>rectory Cambia alla <strong>di</strong>rectory <strong>di</strong> destinazione.<br />

# 7) && "lista And", come sopra<br />

# 8) tar xpvf - Scompatta l’archivio (’x’), mantiene i permessi e<br />

# le proprietà dei file (’p’), invia messaggi<br />

# dettagliati allo stdout (’v’), leggendo i dati<br />

# dallo st<strong>di</strong>n (’f’ seguito da ’-’)<br />

# Attenzione: ’x’ è un comando,<br />

# mentre ’p’, ’v’ ed ’f’ sono opzioni.<br />

# Whew!<br />

# Più elegante, ma equivalente a:<br />

# cd source-<strong>di</strong>rectory<br />

# tar cf - . | (cd ../dest/<strong>di</strong>rectory; tar xpvf -)<br />

#<br />

# Ottengono lo stesso rirultato anche:<br />

# cp -a /source/<strong>di</strong>rectory/* /dest/<strong>di</strong>rectory<br />

# Oppure:<br />

# cp -a /source/<strong>di</strong>rectory/* /source/<strong>di</strong>rectory/.[^.]* /dest/<strong>di</strong>rectory<br />

# Nel caso ci siano file nascosti in /source/<strong>di</strong>rectory.<br />

27

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

Saved successfully!

Ooh no, something went wrong!