0PricingLogin
Linux Command Line & Bash Scripting Mastery · Lesson

Variables and User Input

Learn to define and use variables in your scripts, and how to prompt users for input to make scripts interactive.

What are Variables?

In Bash scripting, variables are like named containers that hold data. Think of them as placeholders for information you want to use or change in your scripts.

They help make your scripts flexible, reusable, and easier to manage by storing values such as text, numbers, or even command outputs.

Declaring & Assigning Variables

To create a variable in Bash, you simply assign a value to a name. There are no special keywords like var or let needed.

  • Use VARIABLE_NAME=value syntax.
  • Important: Do not put spaces around the = sign.
  • Values can be text (strings) or numbers.

Let's try assigning some values:

#!/bin/bash

# Assigning a string
MY_NAME="CoddyKit"

# Assigning a number
LESSON_NUMBER=2

echo "Name: $MY_NAME"
echo "Lesson: $LESSON_NUMBER"

All lessons in this course

  1. First Bash Script & Shebang
  2. Variables and User Input
  3. Conditional Statements (if, else, elif)
  4. Working with Arrays in Bash
← Back to Linux Command Line & Bash Scripting Mastery