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.

# Set variable to pass as parameter to "<strong>di</strong>splay" function.<br />

avar=‘echo ${array[@]}‘ # Convert array back to string variable.<br />

<strong>di</strong>splay "$avar" # Display it.<br />

echo; echo<br />

echo "Generation $generation - $alive alive"<br />

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

then<br />

echo<br />

echo "Premature exit: no more cells alive!"<br />

exit $NONE_ALIVE # No point in continuing<br />

fi #+ if no live cells.<br />

}<br />

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

# main ()<br />

# Load initial array with contents of startup file.<br />

initial=( ‘cat "$startfile" | sed -e ’/#/d’ | tr -d ’\n’ |\<br />

sed -e ’s/\./\. /g’ -e ’s/_/_ /g’‘ )<br />

# Delete lines containing ’#’ comment character.<br />

# Remove linefeeds and insert space between elements.<br />

clear # Clear screen.<br />

echo # Title<br />

echo "======================="<br />

echo " $GENERATIONS generations"<br />

echo " of"<br />

echo "\"Life in the Slow Lane\""<br />

echo "======================="<br />

# -------- Display first generation. --------<br />

Gen0=‘echo ${initial[@]}‘<br />

<strong>di</strong>splay "$Gen0" # Display only.<br />

echo; echo<br />

echo "Generation $generation - $alive alive"<br />

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

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

echo<br />

# ------- Display second generation. -------<br />

Cur=‘echo ${initial[@]}‘<br />

next_gen "$Cur" # Update & <strong>di</strong>splay.<br />

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

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

630

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

Saved successfully!

Ooh no, something went wrong!