Typorithm · medium

Quoting & Expansion

bash-quotingbashquotingarraydefault
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Quoting & Expansion

0%

Basics

Double quotes allow $variable expansion; single quotes are fully literal. ${var:-default} supplies a fallback when var is unset, arr=(*.txt) builds an array from a glob, and ${#arr[@]} returns the array's length.

Quoting controls expansion. Double quotes ("double $name") let the shell expand variables and command substitutions, while single quotes ('single $name') are completely literal — nothing inside is expanded.

${name:-guest} is parameter expansion with a default: if name is unset or empty, guest is used instead, otherwise the variable's value wins. It is the standard way to give a fallback.

files=(*.txt) creates an array by letting the shell expand the *.txt glob into matching filenames, and ${#files[@]} reports how many elements the array holds.

01

Double quotes expand; single quotes are literal.

02

${var:-default} falls back when var is unset or empty.

03

arr=(*.txt) builds an array; ${#arr[@]} is its length.

echo "double $name"
echo 'single $name'
echo "${name:-guest}"
files=(*.txt)
echo "${#files[@]}"

Read the implementation

Connect each part of the code to the concept before you type.

1. Double quotes

Double quotes allow expansion, so $name becomes its value.

echo "double $name"

2. Single quotes

Single quotes are fully literal — $name is printed verbatim, no expansion.

echo 'single $name'

3. Default value

${var:-default} substitutes the default when var is unset or empty.

${name:-guest}

4. Array from glob

arr=(...) makes an array; *.txt is a glob the shell expands into matching filenames.

files=(*.txt)

5. Array length

${#arr[@]} gives the number of elements in the array.

${#files[@]}

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Quoting & Expansion: Lesson & Practice · Typorithm | ApplyDjinn