Variables and their Types

Familiarize yourself with variables in shell environment and their types.

If you have prior programming experience, then you might already be familiar with the basic concepts of Variables. This chapter will briefly summarize all the concepts that you have studied so far and give you hands-on experience on variable assignments. Variables are nothing but placeholders for memory locations. They empower the programmers to quickly store or retrieve data for the successful execution of a program.

In Bash, variables are commonly referred to as Bash Parameters. These parameters can be further categorized into three types; Special Parameters, Positional Parameters, and Shell Variables. In this chapter, we will only cover the latter one as it’s the most important type of variable. In Bash, it is not necessary to declare the type of a variable so a variable can hold anything that we assign to it be it a number, string, or a character.

Types of Variables

Based on their lifetime, range, and uses, the variables can generally be divided into three categories:

  • Shell Variables
  • Local Variables
  • Environment Variables
  • Other Variables

Get hands-on with 1200+ tech skills courses.