5. Bash Syntax and Variables#
This chapter begins the scripting sequence by showing how Bash parses commands, expands values, stores data, and combines arithmetic with string operations.
Syntax: Recognize how Bash separates commands, options, and arguments.
Quoting: Control when spaces, variables, and special characters are interpreted.
Variables: Store values and expand them safely in scripts.
Substitution: Use parameter and command substitution to derive script values.
String and arithmetic operations: Manipulate text and integer values with Bash syntax.
Chapter Video
What are Variables in Bash (5:57) by Microsoft Developer
Hosted on YouTube; property of its original creator, embedded here for educational reference only.
Learning Objectives
By the end of this chapter, you will be able to:
Write Bash commands with correct spacing, quoting, and structure.
Explain how quoting, escaping, and word splitting affect command safety.
Create and run a first Bash script.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Command |
A program, shell builtin, function, or alias invoked by name. |
2 |
Argument |
A value passed to a command after its name. |
3 |
Option |
An argument that modifies command behavior, often beginning with |
4 |
Quoting |
Syntax that controls how Bash interprets spaces and special characters. |
5 |
Single quotes |
Quotes that preserve text literally, including dollar signs. |
6 |
Double quotes |
Quotes that preserve spaces while still allowing selected expansions. |
7 |
Escaping |
Using a backslash to give a special character a literal meaning. |
8 |
Variable |
A named shell value that can be expanded later. |
9 |
Assignment |
Setting a variable with syntax such as |
10 |
Parameter expansion |
Using |
11 |
Command substitution |
Running a command and inserting its output with |
12 |
Environment variable |
A variable exported to child processes. |
13 |
|
A command that places a variable in the environment of child processes. |
14 |
Positional parameter |
A script or function argument referenced as |
15 |
Default value expansion |
A parameter expansion that supplies a fallback when a value is unset or empty. |
16 |
Substring expansion |
A parameter expansion that extracts part of a string. |
17 |
Arithmetic expansion |
The |
18 |
Word splitting |
The shell step that splits unquoted expansion results into separate words. |
19 |
Globbing |
Filename pattern expansion performed by the shell. |
20 |
String length |
The number of characters in a shell value, available with |