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.

Una volta ancora questo <strong>di</strong>mostra che le variabili <strong>Bash</strong> non sono tipizzate.<br />

Esempio 26-2. Impaginare una poesia<br />

#!/bin/bash<br />

# poem.sh: Visualizza in modo elegante una delle poesie preferite<br />

#+ dall’autore del documento.<br />

# Righe della poesia (una strofa).<br />

Riga[1]="I do not know which to prefer,"<br />

Riga[2]="The beauty of inflections"<br />

Riga[3]="Or the beauty of innuendoes,"<br />

Riga[4]="The blackbird whistling"<br />

Riga[5]="Or just after."<br />

# Attribuzione.<br />

Attrib[1]=" Wallace Stevens"<br />

Attrib[2]="\"Thirteen Ways of Looking at a Blackbird\""<br />

# La poesia è <strong>di</strong> Dominio Pubblico (copyright scaduto).<br />

echo<br />

for in<strong>di</strong>ce in 1 2 3 4 5 # Cinque righe.<br />

do<br />

printf " %s\n" "${Riga[in<strong>di</strong>ce]}"<br />

done<br />

for in<strong>di</strong>ce in 1 2 # Attribuzione <strong>di</strong> due righe.<br />

do<br />

printf " %s\n" "${Attrib[in<strong>di</strong>ce]}"<br />

done<br />

echo<br />

exit 0<br />

# Esercizio:<br />

# ---------<br />

# Mo<strong>di</strong>ficate lo script in modo che la poesia da visualizzare<br />

#+ sia presa da un file dati.<br />

Capitolo 26. Array<br />

Gli array hanno una sintassi loro propria ed anche i coman<strong>di</strong> e gli operatori standard <strong>di</strong> <strong>Bash</strong> posseggono<br />

opzioni specifiche adatte per l’uso degli array.<br />

474

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

Saved successfully!

Ooh no, something went wrong!