Variables

Variables are used to store values. In the following equation, two variables—x and y—are given:

x + y = 4

In this particular case, you can infer that the values associated with the variables are numeric. But variables can just as easily be character-based. Variables are used extensively in programming, so more will be discussed later. A variable is a name/value pair. The variable has a name, called a varnamex and y, previously shown—and a value, such as 2 or /home/shell as seen in the following example:

$ echo $HOME
/home/shell

The dollar sign ($) is placed in front of the varname to indicate that you are accessing the value of the variable. It forces the shell to check its table of variables to see whether it contains a variable ...

Get Korn Shell Programming by Example 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.