Cover by William E. Shotts Jr.

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

O'Reilly logo

Variables and Constants

There is an issue with our script, however. Notice how the string System Information Report is repeated? With our tiny script it’s not a problem, but let’s imagine that our script was really long and we had multiple instances of this string. If we wanted to change the title to something else, we would have to change it in multiple places, which could be a lot of work. What if we could arrange the script so that the string appeared only once and not multiple times? That would make future maintenance of the script much easier. Here’s how we could do that:

#!/bin/bash

# Program to output a system information page

title="System Information Report"

echo "<HTML>
         <HEAD>
                <TITLE>$title</TITLE>
         </HEAD>
         <BODY>
                <H1>$title</H1> </BODY> ...

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