27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

# 4*5 #<br />

# 678 #<br />

# #<br />

# 2) A living cell with either 2 or 3 living neighbors remains alive. #<br />

# 3) A dead cell with 3 living neighbors becomes alive (a "birth"). #<br />

SURVIVE=2 #<br />

BIRTH=3 #<br />

# 4) All other cases result in dead cells. #<br />

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

startfile=gen0 # Read the starting generation from the file "gen0".<br />

# Default, if no other file specified when invoking script.<br />

#<br />

if [ −n "$1" ] # Specify another "generation 0" file.<br />

then<br />

if [ −e "$1" ] # Check for existence.<br />

then<br />

startfile="$1"<br />

fi<br />

fi<br />

ALIVE1=.<br />

DEAD1=_<br />

# Represent living and "dead" cells in the start−up file.<br />

# This script uses a 10 x 10 grid (may be increased,<br />

#+ but a large grid will will cause very slow execution).<br />

ROWS=10<br />

COLS=10<br />

GENERATIONS=10<br />

NONE_ALIVE=80<br />

TRUE=0<br />

FALSE=1<br />

ALIVE=0<br />

DEAD=1<br />

avar=<br />

generation=0<br />

# How many generations to cycle through.<br />

# Adjust this upwards,<br />

#+ if you have time on your hands.<br />

# Exit status on premature bailout,<br />

#+ if no cells left alive.<br />

# Global; holds current generation.<br />

# Initialize generation count.<br />

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

let "cells = $ROWS * $COLS"<br />

# How many cells.<br />

declare −a initial<br />

declare −a current<br />

# Arrays containing "cells".<br />

display ()<br />

{<br />

alive=0<br />

# How many cells "alive".<br />

# Initially zero.<br />

declare −a arr<br />

Appendix A. Contributed Scripts 380

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

Saved successfully!

Ooh no, something went wrong!