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.

toglie_zero_iniziale $giorno<br />

giorno=$?<br />

toglie_zero_iniziale $mese<br />

mese=$?<br />

data2=$(tot_giorni $giorno $mese $anno) # Sostituzione <strong>di</strong> comando.<br />

calcola_<strong>di</strong>fferenza $data1 $data2<br />

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

abs $<strong>di</strong>ff # Si accerta che sia positiva.<br />

<strong>di</strong>ff=$valore<br />

echo $<strong>di</strong>ff<br />

exit 0<br />

# Confrontate questo script con<br />

#+ l’implementazione della Formula <strong>di</strong> Gauss in un programma in C presso:<br />

#+ http://buschencrew.hypermart.net/software/date<strong>di</strong>f<br />

Esempio A-8. Creare un “<strong>di</strong>zionario”<br />

#!/bin/bash<br />

# make<strong>di</strong>ct.sh [crea un <strong>di</strong>zionario]<br />

# Mo<strong>di</strong>fica dello script /usr/sbin/mk<strong>di</strong>ct.<br />

# Script originale copyright 1993, <strong>di</strong> Alec Muffett.<br />

#<br />

# Lo script mo<strong>di</strong>ficato incluso nel presente documento si conforma solo<br />

#+ fino a un certo punto con la "LICENSE" document of the "Crack" del pacchetto<br />

#+ a cui lo script originale appartiene.<br />

# Lo script elabora file <strong>di</strong> testo e produce un elenco or<strong>di</strong>nato<br />

#+ delle parole trovate nel(i) file.<br />

# Può essere utile per la compilazione <strong>di</strong> <strong>di</strong>zionari<br />

#+ e per ricerche lessicografiche.<br />

E_ERR_ARG=65<br />

if [ ! -r "$1" ] # Occorre almeno un<br />

then #+ argomento valido.<br />

echo "Utilizzo: $0 file-da-elaborare"<br />

exit $E_ERR_ARG<br />

fi<br />

# SORT="sort" # Non più necessario per definire<br />

#+ le opzioni <strong>di</strong> sort.<br />

#+ Mo<strong>di</strong>fica allo script originale.<br />

620

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

Saved successfully!

Ooh no, something went wrong!