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

Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.