Store Data
Store values that can be reused throughout the script.
Shell Script · Variables
Shell Scripting · Lesson 6
Understand variables in shell scripting. System and user defined variables. Rules for naming variables. Using variables in real automation scripts.
Variables are named containers used to store data in shell scripting. They allow scripts to save values and reuse them whenever needed.
A variable can store:
Shell variables are dynamically created and do not require a specific data type declaration.
Syntax:
variable_name=valueImportant: Do not use spaces around the "=" operator.
Store values that can be reused throughout the script.
Change a value once and reuse it everywhere.
Scripts behave dynamically based on variable values.
Shell scripting mainly uses three types of variables:
Local variables are available only inside the current shell or script where they are created.
Environment variables are shared with child processes and system programs.
Read-only variables cannot be modified after assignment.
Variables are created by assigning a value without spaces around '='.
Variables can store numbers and be used in calculations.
Variables can be reassigned with new values.
Variables can also store the output of commands.
To access the value of a variable, use the $ symbol before the variable name.
name = "Linux"$ while reading variable values.name and print it.age and update its value.date command inside a variable.readonly.env.Next lesson: User Input (read command)