Study guide

2.1a Bash Shell, Command Syntax & Variables

LPI Linux Essentials Certificate 010-160

Track your progress as you read

Finished sections get a check mark.

1 Introduction & Exam Overview

1.1 Current Exam Facts 1.2 Study Strategy & Blueprint Weights

2 Topic 1: The Linux Community and a Career in Open Source

1.1 Linux Evolution and Popular Operating Systems 1.2 Major Open Source Applications 1.3 Open Source Software and Licensing 1.4 ICT Skills and Working in Linux

3 Topic 2 Part A: Command Line Basics & Getting Help

2.1a Bash Shell, Command Syntax & Variables 2.1b Quoting, History & Safe Command Syntax 2.2 Using the Command Line to Get Help

4 Topic 2 Part B: Directories, Listing & File Operations

2.3 Using Directories and Listing Files 2.4 Creating, Moving and Deleting Files

5 Topic 3 Part A: Archiving & Searching Data

3.1 Archiving and Compression on the Command Line 3.2a Pipes, Redirection, and Basic Regular Expressions 3.2b grep and Text Extraction Tools

6 Topic 3 Part B: Turning Commands into Scripts

3.3a Script Basics: Shebang, Variables, and Arguments 3.3b Loops, Exit Status, and Simple Conditionals 3.3c Editors, chmod +x, and Running Scripts

7 Topic 4 Part A: Choosing an OS, Hardware & FHS Basics

4.1 Choosing an Operating System 4.2 Understanding Computer Hardware 4.3a Where Programs and Configuration Live (FHS Basics)

8 Topic 4 Part B: Processes, Logs & Networking

4.3b Processes, Memory & Logs 4.4 Your Computer on the Network

9 Topic 5: Security and File Permissions

5.1 Basic Security and Identifying User Types 5.2 Creating Users and Groups 5.3 Managing File Permissions and Ownership 5.4 Special Directories and Files

2.1a Bash Shell, Command Syntax & Variables

Key Takeaways Explain This Topic AI

Bash is the default interactive shell on most Linux distributions and reads each line as a command name followed by options and arguments

echo prints text or expanded variable values; unquoted $NAME expands a variable, while echo alone with no arguments prints a blank line

PATH is a colon-separated list of directories the shell searches for executable commands when you type a bare command name

export promotes a shell variable into an environment variable so child processes inherit it; without export, children do not see the value

type reports whether a name is a builtin, an alias, a function, a hashed binary, or not found — useful before you assume a command is an external program

Last updated: July 2026

The Linux Essentials exam expects you to work comfortably at a text prompt. On nearly every modern distribution that prompt is provided by Bash (the Bourne Again SHell). Bash reads a line, splits it into words, expands special tokens, then runs the resulting command. Mastering that pipeline — syntax, variables, and how the shell finds programs — is the core of objective 2.1.

What the Shell Actually Does

When you open a terminal, Bash prints a prompt (often ending in $ for a normal user or # for root) and waits. You type a command and press Enter. Conceptually Bash then:

Tokenizes the line into words separated by spaces or tabs.

Expands variables ( $HOME ), wildcards, and command substitutions where quoting allows it.

Resolves the first word as the command name (builtin, alias, function, or external file).

Passes the remaining words as options and arguments.

Waits for the command to finish (unless you background it — beyond Essentials depth).

A typical line looks like: ls -la /etc

  • Piece Role Example
  • Command Program or builtin to run ls
  • Options / switches Modify behavior; often start with - or -- -la
  • Arguments Targets such as files or directories /etc

Order matters for readability and for many tools: command first, then options, then operands. Some utilities accept options after arguments, but the exam-safe habit is options before operands .

  • echo : Print What the Shell Sees
  • echo writes its arguments to standard output, separated by spaces, and ends with a newline: echo Hello Linux
  • # Hello Linux
  • echo "HOME is $HOME"
  • # HOME is /home/student

Because echo prints after expansion, it is the simplest way to inspect what Bash did with a variable or a quoted string. Options you may see:

  • Option Effect
  • n Suppress the trailing newline
  • e Enable backslash escapes such as \n and \t (implementation-dependent; know that behavior varies)

For Essentials, focus on using echo to display literal text and expanded $variables .

Variables: Shell vs Environment

A shell variable exists only inside the current Bash process. Assign with NAME=value — no spaces around = : COURSE=LinuxEssentials

  • echo $COURSE
  • # LinuxEssentials

An environment variable is a shell variable that has been marked for export. Child processes (commands you launch) inherit the environment. Shell-only variables do not appear in children. SECRET=local-only

export PUBLIC=visible-to-children

  • bash -c 'echo SECRET=$SECRET PUBLIC=$PUBLIC'
  • # SECRET= PUBLIC=visible-to-children

Concept How you set it Visible to child processes?

  • Shell variable NAME=value No
  • Environment variable export NAME=value or NAME=value then export NAME Yes

Common environment variables you should recognize:

  • Variable Typical meaning
  • HOME Your home directory
  • USER / LOGNAME Login name
  • SHELL Path to your login shell
  • PATH Directories searched for commands
  • PWD Current working directory
  • PATH : How Bash Finds Commands

When you type ls without a slash, Bash does not magically know /bin/ls . It walks the directories listed in PATH , separated by colons: echo $PATH

# /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

The first matching executable wins. If nothing matches, Bash reports command not found . Putting . (the current directory) in PATH is discouraged for security; run local scripts with ./script.sh instead.

To temporarily prepend a directory: export PATH="$HOME/bin:$PATH"

Children of this shell then search $HOME/bin first.

export and type

export either marks an existing variable for the environment or assigns and exports in one step: export EDITOR=nano

export PATH="/opt/tools/bin:$PATH"

type tells you how Bash would run a name — critical when aliases or builtins shadow external binaries: type echo

# echo is a shell builtin

  • type ls
  • # ls is /bin/ls (or "ls is aliased to ...")
  • type notacommand
  • # bash: type: notacommand: not found
  • type result Meaning
  • shell builtin Implemented inside Bash ( cd , echo , export , type itself)
  • aliased to … Shortcut defined with alias
  • hashed / is /path External executable on disk
  • not found Nothing on PATH (and not a builtin/alias)
  • Command Substitution Awareness

Command substitution runs a command and inserts its output into the outer command line. Modern form uses $(...) : echo "Today is $(date +%Y-%m-%d)"

echo "Kernel: $(uname -r)"

Older textbooks show backticks `date` ; prefer $(...) because it nests cleanly. For Essentials, know that substitution happens before the outer command runs, and that quoting around $(...) preserves spaces in the captured output.

  • Worked Mini-Lab # 1. Create a shell-only variable
  • LAB=essentials
  • echo "LAB=$LAB"
  • # 2. Export so a child shell sees it
  • export LAB
  • bash -c 'echo child sees LAB=$LAB'
  • # 3. Inspect how commands resolve
  • type pwd
  • type /bin/pwd
  • # 4. Confirm PATH search order
  • echo $PATH
  • which ls # often shows the same path type would report for an external binary

If bash -c prints an empty LAB , you forgot export . That single distinction — shell versus environment — is a frequent exam trap.

Exam Focus

Expect fill-in and multiple-choice items on: correct NAME=value syntax (no spaces), what export changes, reading PATH , and using echo / type to inspect the environment. You do not need deep scripting yet — that arrives in Topic 3 — but you must treat the shell as a programmable environment, not just a place to type ls .