Variable Basics
In this page:
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
#!/bin/bash
name="Alice"
age=30
echo "Name: $name"
echo "Age: $age"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: