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.

let "generation += 1" # Increment generation count.<br />

# ------ Main loop for <strong>di</strong>splaying subsequent generations -----while<br />

[ "$generation" -le "$GENERATIONS" ]<br />

do<br />

Cur="$avar"<br />

next_gen "$Cur"<br />

let "generation += 1"<br />

done<br />

# ==============================================================<br />

echo<br />

exit 0<br />

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

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

# The grid in this script has a "boundary problem."<br />

# The the top, bottom, and sides border on a void of dead cells.<br />

# Exercise: Change the script to have the grid wrap around,<br />

# + so that the left and right sides will "touch,"<br />

# + as will the top and bottom.<br />

#<br />

# Exercise: Create a new "gen0" file to seed this script.<br />

# Use a 12 x 16 grid, instead of the original 10 x 10 one.<br />

# Make the necessary changes to the script,<br />

#+ so it will run with the altered file.<br />

#<br />

# Exercise: Mo<strong>di</strong>fy this script so that it can determine the grid size<br />

#+ from the "gen0" file, and set any variables necessary<br />

#+ for the script to run.<br />

# This would make unnecessary any changes to variables<br />

#+ in the script for an altered grid size.<br />

Esempio A-11. File dati per “Game of Life”<br />

# This is an example "generation 0" start-up file for "life.sh".<br />

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

# The "gen0" file is a 10 x 10 grid using a period (.) for live cells,<br />

#+ and an underscore (_) for dead ones. We cannot simply use spaces<br />

#+ for dead cells in this file because of a peculiarity in <strong>Bash</strong> arrays.<br />

# [Exercise for the reader: explain this.]<br />

#<br />

# Lines beginning with a ’#’ are comments, and the script ignores them.<br />

__.__..___<br />

___._.____<br />

____.___..<br />

_._______.<br />

____._____<br />

..__...___<br />

____._____<br />

___...____<br />

631

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

Saved successfully!

Ooh no, something went wrong!