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 />

A−7). It can even be used to generate prime numbers, (see Example A−17). Modulo turns up<br />

surprisingly often in various numerical recipes.<br />

Example 8−1. Greatest common divisor<br />

#!/bin/bash<br />

# gcd.sh: greatest common divisor<br />

# Uses Euclid's algorithm<br />

# The "greatest common divisor" (gcd) of two integers<br />

#+ is the largest integer that will divide both, leaving no remainder.<br />

# Euclid's algorithm uses successive division.<br />

# In each pass,<br />

#+ dividend

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

Saved successfully!

Ooh no, something went wrong!