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.

}<br />

if [ ${array[$t_top]} = "$ALIVE1" ]<br />

then<br />

let "count += 1"<br />

fi<br />

fi<br />

let "row = $r + 1" # Count bottom row.<br />

IsValid $t_bot $row<br />

if [ $? -eq "$TRUE" ]<br />

then<br />

if [ ${array[$t_bot]} = "$ALIVE1" ]<br />

then<br />

let "count += 1"<br />

fi<br />

fi<br />

done<br />

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

if [ ${array[$cell_number]} = "$ALIVE1" ]<br />

then<br />

let "count -= 1" # Make sure value of tested cell itself<br />

fi #+ is not counted.<br />

return $count<br />

next_gen () # Update generation array.<br />

{<br />

local array<br />

local i=0<br />

array=( ‘echo "$1"‘ ) # Convert passed arg to array.<br />

while [ "$i" -lt "$cells" ]<br />

do<br />

IsAlive "$1" $i ${array[$i]} # Is cell alive?<br />

if [ $? -eq "$ALIVE" ]<br />

then # If alive, then<br />

array[$i]=. #+ represent the cell as a period.<br />

else<br />

array[$i]="_" # Otherwise underscore<br />

fi #+ (which will later be converted to space).<br />

let "i += 1"<br />

done<br />

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

# Why was the above line commented out?<br />

629

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

Saved successfully!

Ooh no, something went wrong!