Lazo Lab Sign up

Linux & the Command Line / Servers and scripts

Lesson 28 of 30

Variables and loops in bash

Bash variables have no spaces around =, and you read them with $. Always quote "$variables" to handle spaces safely.

Key points

  • name=value (no spaces)
  • Use "$name" with quotes
  • for i in {1..5}; do ...; done
name="Lazo"
for i in {1..3}; do
  echo "$i: hello $name"
done
Watch a video on thisOpens YouTube search results for “Variables and loops in bash” in a new tab

Quiz · +10 XP

Which is a correct bash variable assignment?

Log in to save progress and earn XP.