SI Learning
0% read · Practice is tracked separately
← My learning
Version 1 · Chapter 7Reading mode

Make the shell predictable

By the end: Understand quoting, environment variables, history, and the difference between printing and executing.

The idea

Single quotes preserve literal text; double quotes allow variable expansion while keeping spaces in one argument. > replaces a destination file and >> appends. Environment variables travel to child processes only when exported. Keep credentials out of examples, terminal history, and shared screenshots.

Your command toolkit

echo

What it solves: Print a short message.

bash
echo 'Hello, terminal'

For precise formatting or strings beginning with options, prefer printf. echo behavior around escapes varies across shells.

printf

What it solves: Format output consistently.

bash
printf 'Hello, %s\n' 'Asha'

Keep the format string fixed and pass variable data as arguments. This avoids treating percent signs in data as formatting instructions.

alias

What it solves: Create a convenient interactive shortcut.

bash
alias ll='ls -lah'
alias ll

An alias belongs to this shell unless saved in a startup file. Use clear commands rather than personal aliases in shared scripts.

history

What it solves: Review commands already entered.

bash
history 5

History behavior depends on Bash settings. Review it privately; it may contain sensitive arguments.

!!

What it solves: Understand Bash's previous-command expansion.

bash
printf 'practice\n'
!!:p

In interactive Bash with history expansion enabled, !!:p prints the previous command without running it. Bare !! executes it again; inspect before repeating.

env

What it solves: Set an environment for one process.

bash
env SI_MODE=practice printenv SI_MODE

The variable applies to the child process, leaving your shell's SI_MODE unchanged. Avoid dumping the full environment when it may contain secrets.

printenv

What it solves: Read one exported variable.

bash
printenv PATH

PATH lists directories searched for executables. A missing variable produces no value and a nonzero status.

export

What it solves: Pass a value to child processes.

bash
export SI_COURSE=linux
bash -c 'printf "%s\n" "$SI_COURSE"'

A child inherits the exported value. Changes inside a child do not update its parent shell.

exit

What it solves: Leave a shell with a status.

bash
bash -c 'exit 0'
printf 'Child status: %s\n' "$?"

This example exits a child shell only. Running exit directly would close your current shell or SSH session.

tty

What it solves: Check whether input is a terminal.

bash
tty

Prints the terminal device for standard input, or reports that input is not a terminal. Piped and redirected input can change the result.

Before you move on

Try the guided lab below. Compare the result with the explanation, then record your reasoning in the workbook. A missing optional program or a restricted environment is something to explain, not a reason to change system settings blindly.

Practice with evidence

  1. Predict the result
  2. Run the guided lab
  3. Compare the output
  4. Explain your choice

A worked example

Guided lab

bash
SI_LABEL='Linux practice'
printf 'One argument: <%s>\n' "$SI_LABEL"
env SI_LABEL='child only' printenv SI_LABEL
printf 'Parent still: %s\n' "$SI_LABEL"

What to expect: Linux practice remains one argument. The child prints child only; the parent still prints Linux practice.

Make it yours: Explain single versus double quotes and show the difference between a one-command environment value and an exported value.

Read further

Apply what you learned

Your private practice

Does changing an environment variable inside a child process update its parent?

Answers are private. Completion requires the correct knowledge-check answer and a written response when an activity is included.

Restore a downloaded workbook

Choose a recovery file for this course and version. Review the recovered copy before saving it to your account.

Ask a question or report a problem

Describe what needs attention. Your private answer is shared only if you select the option below.

All learning paths
SI CENTRALIZATION · LEARN

Linux Command Line: from first command to confident practice

24 chapters · Your own pace

0 of 24 chapters complete