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.

then<br />

let "h /= 2" # Divide per 2.<br />

else<br />

let "h = h*3 + 1" # Moltiplica per 3 e aggiunge 1.<br />

fi<br />

COLONNE=10 # Visualizza 10 numeri per riga.<br />

let "interruzione_riga = i % $COLONNE"<br />

if [ "$interruzione_riga" -eq 0 ]<br />

then<br />

echo<br />

fi<br />

done<br />

echo<br />

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

# Per ulteriori informazioni su questa funzione matematica,<br />

#+ ve<strong>di</strong> "Computers, Pattern, Chaos, and Beauty", by Pickover, p. 185 ff.,<br />

#+ presente in bibliografia.<br />

exit 0<br />

Esempio A-7. days-between: calcolo del numero <strong>di</strong> giorni intercorrenti tra due date<br />

#!/bin/bash<br />

# days-between.sh: Numero <strong>di</strong> giorni intercorrenti tra due date.<br />

# Utilizzo: ./days-between.sh [M]M/[G]G/AAAA [M]M/[G]G/AAAA<br />

#<br />

# Nota: Script mo<strong>di</strong>ficato per tener conto dei cambiamenti avvenuti<br />

#+ in <strong>Bash</strong> 2.05b, che hanno chiuso una falla che consentiva la<br />

#+ restituzione <strong>di</strong> gran<strong>di</strong> interi negativi.<br />

ARG=2 # Sono attesi due argomenti da riga <strong>di</strong> comando.<br />

E_ERR_PARAM=65 # Errore <strong>di</strong> parametro.<br />

ANNORIF=1600 # Anno <strong>di</strong> riferimento.<br />

SECOLO=100<br />

GPA=365<br />

AGG_GPA=367 # Aggiustamento per anno bisestile e frazione.<br />

MPA=12<br />

GPM=31<br />

FREQ_BISESTILE=4<br />

MAXVALRIT=255 # Massimo intero positivo consentito<br />

#+ come valore <strong>di</strong> ritorno <strong>di</strong> una funzione.<br />

<strong>di</strong>ff= # Variabile globale per la <strong>di</strong>fferenza delle date.<br />

valore= # Variabile globale per il valore assoluto.<br />

giorno= # Variabili globali per giorno, mese, anno.<br />

mese=<br />

617

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

Saved successfully!

Ooh no, something went wrong!