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:


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


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