typestar

Variables & quoting in Bash

Assignment, expansion, and the quoting that keeps words whole.

# assignment has no spaces; quoting decides how a value expands
name="Ada Lovelace"
count=3

echo "double quotes expand: $name typed $count runs"
echo 'single quotes do not: $name'

# always quote expansions: unquoted, the space would split the word
greeting="hello, ${name}"
echo "$greeting"

How it works

  1. Assignment has no spaces around =; that rule is absolute.
  2. Double quotes expand $name; single quotes keep it literal.
  3. Quoting expansions stops the shell splitting on the space.

Keywords and builtins used here

The run, in numbers

Lines
10
Characters to type
292
Tokens
30
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 20 seconds.

Type this snippet

Step 1 of 3 in Variables & quoting, step 1 of 26 in Language basics.

Next →