Welcome back to the world of shell scripting. In the previous lesson, you crafted your very first shell script that printed "Hello, World!" to the screen. Today, we will take the next step by exploring how to use variables in shell scripts. This lesson will introduce you to variable declaration, reassignment, and some basic arithmetic operations.
Using variables can make your scripts more dynamic and flexible, allowing you to store information, reuse values, and perform calculations. Let's get started!
Variables in shell scripts are used to store data that can be reused throughout the script. To define a variable in a shell script, you use the syntax:
An important distinction of bash is there cannot be spaces before or after the = sign.
To access the value of a variable, use a $ before the variable name.
Let's take a look at an example:
greeting="Hello": This line creates a variable namedgreetingand sets its value to "Hello."name="World": Another variable namednameis created and assigned the value "World."
