The Basics of Variables and Arrays

Variables are containers that have names and hold information, either numbers or text. Variable names can consist of letters, numbers, and underscores (_). The name can begin with a letter or an underscore, but not a number. To create a variable, store information in it. The following are valid commands that store information:

var1=3
_var2=Hello
full_name="John Smith"

No space is allowed before or after the =. Notice the first two commands do not use quotes around the information. The third command requires quotes because it includes a space. Without quotes, the shell would store John and see Smith as a new command.

When you use a variable value, you precede the variable name with a $, such as:

					echo $_var2 ...

Get Spring Into Linux® 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.