Premium lesson

Storing Data With Variables in Bash

Scripting·3 min read·Jan 1, 2025

In programming, a variable is a named container used to store data referred to as a value.

It can be used to store a wide range of information, such as a filename, a date, a counter, a line of text, and pretty much anything else you can think of.

Depending on certain conditions, this value may change during the execution of the script and be updated either by the developer through instructions, the user through input, or the script itself through logic.

Data types

Bash variables can essentially store 4 different data types: characters, strings, numbers, arrays.

Characters

A character is a unit of text that represents a single symbol or letter.

Characters can be assigned directly without quotes, enclosed in single quotes, or enclosed in double quotes:

char=achar='b'char="c"

Strings

A string is a sequence of characters often used to represent words and sentences.

Single word strings can be assigned directly without quotes, enclosed in single quotes, or enclosed in double quotes:

string=Hellostring='Hello'string="Hello"
icon light bulb key

Unlock the CLI & Scripting with Bash module

Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.

You get immediate access to:

  • 34 focused lessons across the CLI and Bash
  • 4 real-world projects with commented solutions
  • Ongoing updates to this bundle
  • Lifetime access to this bundle
Unlock this module