Working with Variables

Two types of variables can be used in shell programming:

  • Scalar variables

  • Array variables

Scalar variables can hold only one value at a time. Array variables can hold multiple values. This section explores the use of both types of variables.

Scalar Variables

Scalar variables are defined as follows:

							name=value
						

Here name is the name of the variable, and value is the value that the variable should hold. For example,

FRUIT=peach

defines the variable FRUIT and assigns it the value peach.

Scalar variables are often referred to as name-value pairs, because a variable's name and its value can be thought of as a pair.

Variable ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.