← Back to Bash Course | Chapter 2: Variables & Types | Lesson 1 of 13

Variable Basics

In this page:

  1. Variable Basics

Variable Basics

Bash variables are assigned with name=value and no spaces around the =. You read a variable's value by prefixing it with $, like $name. Bash has no static types — every variable is stored as a string internally, even when it holds something that looks numeric.

Warning: name = value (with spaces) is a syntax error — Bash interprets it as trying to run a command called name.

Example: Variable Basics

bash
#!/bin/bash
name="Alice"
age=30

echo "Name: $name"
echo "Age: $age"

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.