Writing and Executing Scripts

What is a script? If you’re not a programmer, it can all be rather puzzling. A script is a set of instructions to do something, which are executed by the computer. To demonstrate what happens, get your computer to show its command-line prompt, start up a word processor, and type:

#! /bin/sh
echo "have a nice day"

Save this as fred, and make it executable by doing:

chmod +x fred

Run it with the following:

./fred
@echo off
echo "have a nice day"

The odd first line turns off command-line echoing (to see what this means, omit it). Save this as the file fred.bat, and run it by typing fred.

In both cases we get the cheering message have a nice day. If you have never written a program before — you have now. It may seem one thing to write a program that you can execute on your own screen; it’s quite another to write a program that will do something useful for your clients on the Web. However, we will leap the gap.

Get Apache: The Definitive Guide, 3rd Edition 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.