Content Type: Variable Attributes
Learn how variable attributes work in Bash.
We'll cover the following
Attributes
The Bash language does not have a type system. It stores all scalar variables in memory as strings. At the same time, Bash has arrays. They are composite types, because an array is a combination of strings.
When we declare a variable in Bash, we should choose if it is scalar or composite. We make this choice by specifying the metadata for the variable. Such metadata is called attributes. The attributes also define the constancy and scope of a variable.
The declare
Bash built-in specifies the variable attributes. When we call it without parameters, declare
prints all local and environment variables. The set
command prints the same output.
The declare
command has the -p
option. The option adds variable attributes to the output data.
If we need information on a particular variable, we pass its name to the declare
command. Below is an example of the PATH
variable:
declare -p PATH
Try the commands discussed in this lesson in the terminal below.
Get hands-on with 1200+ tech skills courses.