Getting Started
Hello
Printing Text
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"
name ← Ada
3name="Ada"4echo "Hello, $name"values this stepAdanameecho "Hello, $name"
3name="Ada"4echo "Hello, $name"5echo "Shell: bash"outputHello, Adavalues this stepAdanameecho "Shell: bash"
4echo "Hello, $name"5echo "Shell: bash"outputShell: bash
Follow the Output
nameis set toAda.- Bash expands
$nameinsideecho "Hello, $name". - The first
echoprintsHello, Ada. - The second
echoprintsShell: 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.