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.

-x export<br />

-x var=$valore<br />

declare -f nome_funzione<br />

Un declare -f nome_funzione elenca solo la funzione specificata.<br />

declare -x var3<br />

Dichiara la variabile come esportabile al <strong>di</strong> fuori dell’ambiente dello script stesso.<br />

declare -x var3=373<br />

Capitolo 9. Variabili riviste<br />

Il comando declare consente <strong>di</strong> assegnare un valore alla variabile mentre viene <strong>di</strong>chiarata,<br />

impostando così anche le sue proprietà.<br />

Esempio 9-21. Utilizzare declare per tipizzare le variabili<br />

#!/bin/bash<br />

funz1 ()<br />

{<br />

echo Questa è una funzione.<br />

}<br />

declare -f # Elenca la funzione precedente.<br />

echo<br />

declare -i var1 # var1 è un intero.<br />

var1=2367<br />

echo "var1 <strong>di</strong>chiarata come $var1"<br />

var1=var1+1 # La <strong>di</strong>chiarazione <strong>di</strong> intero elimina la necessità <strong>di</strong><br />

#+ usare ’let’.<br />

echo "var1 incrementata <strong>di</strong> 1 <strong>di</strong>venta $var1."<br />

# Tentativo <strong>di</strong> mo<strong>di</strong>ficare il valore <strong>di</strong> una variabile <strong>di</strong>chiarata come intero.<br />

echo "Tentativo <strong>di</strong> mo<strong>di</strong>ficare var1 nel valore in virgola mobile 2367.1."<br />

var1=2367.1 # Provoca un messaggio d’errore, la variabile non cambia.<br />

echo "var1 è ancora $var1"<br />

echo<br />

140

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

Saved successfully!

Ooh no, something went wrong!