O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Treating Programs as Functions

If you've ever written even a very simple DOS batch file or Unix shell script, you're familiar with the idea of calling an external program as if it were a function. That's primarily what shell scripts are for:

#!/bin/sh

# A typical Unix shell script
echo "I'm going to call two other programs now."
prog1       # execute a program named prog1
prog2       # then another program named prog2
echo "All done."

We need to make note of two things before moving on. The first point is that it doesn't matter what language those external programs were written in. They might be compiled programs, Ruby scripts, or scripts in some other language. Secondly, the operation of prog1 and prog2 is sequential. In other words, prog1 has to finish ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required