Bash scripts often start by assigning a value and printing it. This replay shows the shell expanding a variable inside a command argument.

Program

Play the script to watch name receive a value, expand inside echo, and produce stdout.

hello.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash

name="Ada"
echo "Hello, $name"
echo "Shell: bash"
  1. name ← Ada

    3name="Ada"4echo "Hello, $name"
    values this stepAdaname
  2. echo "Hello, $name"

    3name="Ada"4echo "Hello, $name"5echo "Shell: bash"
    outputHello, Ada
    values this stepAdaname
  3. echo "Shell: bash"

    4echo "Hello, $name"5echo "Shell: bash"
    outputShell: bash

Follow the Output

  1. name is set to Ada.
  2. Bash expands $name inside echo "Hello, $name".
  3. The first echo prints Hello, Ada.
  4. The second echo prints Shell: bash. | command text | value used | stdout line | | --- | --- | --- | | echo "Hello, $name" | Ada | Hello, Ada | | echo "Shell: bash" | literal text | Shell: bash |
variable expansion Bash replaces `$name` with the current value before running the command.
stdout The standard output stream is where commands write normal visible results.

Exercise: hello.sh

Reproduce the two output lines, then identify which line came from variable expansion and which line was literal text.