← Lessons/Variables & Output
← Variables & Output

Greet by name

Learn

Variables: a labelled box

A variable is a name you attach to a value so you can use it again later, like a sticky label on a box. To read it back, put a $ in front of the label. The shell replaces $city with whatever's inside; this is called expansion:

city="Lisbon"           # the label `city` now points at the text "Lisbon"
echo "Hello, $city"     # → Hello, Lisbon

The rule that bites every beginner: no spaces around the =. To Bash a space separates a command from its arguments, so city = "Lisbon" means "run the command city with the arguments = and Lisbon".

Quotes matter. Double quotes "…" still expand $variables; single quotes '…' are completely literal ('Hello, $city' prints the dollar sign). The habit to build: wrap values in double quotes. They let variables expand while protecting a value that contains spaces from being split into separate words.

echo prints a line; printf does the same with more formatting control.

In the editor, assign a variable name set to Ada, then print a line (with echo or printf) that reads exactly Hello, Ada.

$ bash solution.sh
Loading...

Output

Run your solution to see its output here.