A command receives arguments after Bash has processed your input. Quoting can preserve literal text; an unquoted filename pattern can become several actual names. To predict the operation, inspect those resulting arguments instead of counting the visible words in the line you typed.
This lesson makes argument boundaries visible with harmless printf output.
You will compare quote forms, read the existing home-directory value, and
select filenames from an exact four-file fixture. Patterns are used only for
printing and read-only inspection. Creation and cleanup always name the
specific files; no shell settings or profile files are changed.
1. Check the guest and the bounded Bash settings
Complete Remove only the practice files you intend first. Use the ordinary Bash account in the checked Ubuntu guest. The already taught identity and origin checks must establish a nonzero user ID, your expected username, Bash, and the intended builtin/utilities. Run each command one line at a time, read its result, and stop after an unexpected error before running the next line:
id -u
id -un
ps -p $ -o comm=
type printf set shopt declare mkdir touch ls rm rmdir
Require printf, set, shopt and declare to be Bash builtins, and the
listed distribution utilities to resolve to their expected installed origins.
Resolve an unexpected command origin before proceeding. Preserve an understood
color-only listing alias. Record the ordinary username for the entry checks.
Filename matching depends on shell settings. This task uses the following bounded baseline, not every possible Bash configuration. Inspect it read-only; do not turn options on or off to make your results fit an example.
First, set -o with no option name after it lists shell-option states.
This inspection changes no setting. Locate these three entries before running
the remaining checks:
set -o
| Entry | Required state and relevance |
|---|---|
noglob | off: filename expansion is enabled. |
errexit | off: the expected nonzero inspection results below should not end this ordinary practice shell. |
nounset | off: use the declared ordinary Bash baseline, not altered unset-value error behavior. |
If the states differ or are unclear, stop and reconcile the declared guest
setup without changing them in this lesson. Then inspect four matching options.
shopt -p prints their settings; it does not apply a change. The printed lines
look like commands, but read them as output; do not execute them.
shopt -p nullglob failglob dotglob nocaseglob
Each named option should be shown off, normally as shopt -u followed by its
name. The inspection can return a nonzero status because options are off; that
is not by itself a failed baseline.
| Off option | Behavior used in this lesson |
|---|---|
nullglob | An unmatched pattern is not silently removed from the argument list. |
failglob | An unmatched pattern does not become a shell expansion error. |
dotglob | Ordinary matching does not include leading-dot names unless the pattern explicitly selects that leading dot. |
nocaseglob | Matching is case-sensitive. |
GLOBIGNORE is an optional existing Bash setting that can filter filename
matches. This fixture assumes it is unset. declare -p GLOBIGNORE only asks
Bash to display that named setting's declaration; it does not assign one.
declare -p GLOBIGNORE
The expected result is a diagnostic that the name is not found, meaning the optional setting is unset. This is not a file-permission problem. If a value is declared, stop and reconcile the baseline; do not assign or unset it here. These settings checks establish assumptions, but you must still compare the actual printed arguments with the fixture.
2. Create exactly four empty filename inputs
The exercise owns ~/linux-practice/quote-and-expand-arguments/. Use the taught
ls -ld checks without trailing slashes: existing home and shared-root entries
must be ordinary directories owned by the expected account, not links.
ls -ld ~
ls -ld ~/linux-practice
ls -ld ~/linux-practice/quote-and-expand-arguments
The exercise name must be absent for this fresh-start path. If it exists, inspect the resume section instead of overwriting anything. Once absence is confirmed, create and inspect only that directory:
mkdir ~/linux-practice/quote-and-expand-arguments
ls -ld ~/linux-practice/quote-and-expand-arguments
Require error-free creation and the expected directory/owner record. Enter it and inspect location separately from file creation:
cd ~/linux-practice/quote-and-expand-arguments
pwd
ls -a
Require the recorded shared practice-root path followed by
/quote-and-expand-arguments, with only . and .. in the directory. Record
this full path. Stop after a failed change or unexpected result.
The complete supplied fixture is four intentionally empty regular files:
day1.txt, day2.txt, day notes.txt and --draft.txt. Their names, not text
contents, are this lesson's input. The already taught touch creates a missing
file without inserting lesson text; use it only after the fresh-state checks.
Before using the leading-hyphen name, distinguish two kinds of processing.
Quotes keep spaces or other quoted characters together for Bash, but they do
not prevent a program from treating a leading hyphen as an option. For these
GNU utilities, a standalone -- ends options; the following words are
operands. In the line below, -- is the option boundary and --draft.txt is
one of the actual filenames. The boundary does not disable Bash expansion.
touch -- day1.txt day2.txt 'day notes.txt' --draft.txt
Inspect the exact entries and complete inventory:
ls -ld -- day1.txt day2.txt 'day notes.txt' --draft.txt
ls -a
Require those four names only, besides the dot entries. Each must have regular
type -, link count 1, the expected owner and size zero. A link, unknown
owner, additional name or nonempty reused file is not the supplied fresh state.
Keep all four files until the independent task is finished.
3. Display the data arguments clearly
Bash's printf was introduced earlier. Here its first argument is a fixed
format, '<%s>\n': print a literal <, the next string at %s, a literal >,
then a newline. Single quotes pass that format intact to printf, which
interprets \n. It reuses the format for additional supplied data arguments.
For these supplied nonempty arguments, each output line frames one value. The angle brackets are display markers, not part of the original arguments. Predict the number of data arguments before running:
printf '<%s>\n' 'day notes.txt'
printf '<%s>\n' day notes.txt
The first prints <day notes.txt> on one line. Its single-quoted pathname is
one data argument. The second prints <day> and <notes.txt> on two lines:
unquoted spaces split the typed words. Printing those words does not create
files called day or notes.txt.
This display is not a universal argument counter. With no data arguments,
printf still applies the format and supplies an empty value for %s. A
deliberate empty-string argument produces the same visible result:
printf '<%s>\n'
printf '<%s>\n' ''
Each prints <>. In the first, no data argument was supplied; in the second,
the empty pair of quotes supplies one empty argument. Do not infer an empty
argument set from a blank-looking formatted result. Our filename tests also
use the declared options and known inventory to explain what was supplied.
4. Compare quotes and one-character escaping
Single quotes preserve the enclosed text literally. Double quotes also keep spaces in one argument and prevent filename-pattern matching, but they allow the specific parameter expansion introduced in the next section. Outside quotes, a backslash can protect the following character; here it keeps one space inside the same word.
Predict these three results, then compare them:
printf '<%s>\n' 'day notes.txt'
printf '<%s>\n' "day notes.txt"
printf '<%s>\n' day\ notes.txt
All three supply one data argument, day notes.txt. The quote characters or
protecting backslash are removed during shell processing. Backslash does not
have identical behavior in every quote context: inside single quotes it is
literal text. The shown backslash-space example is specifically outside quotes.
5. Read the existing home value without changing it
HOME is the existing home-directory value supplied by the guest's login and
session setup. Bash uses it for operations such as its leading-tilde home
shortcut. We are reading that existing value; we are not assigning a variable
or changing the account's home. A later lesson teaches assignment and export.
A dollar sign followed by the name, $HOME, requests this value through
parameter expansion. Inside double quotes, the expansion stays one argument.
Inside single quotes, the dollar sign and letters stay literal. Predict:
printf '<%s>\n' "$HOME"
printf '<%s>\n' '$HOME'
The first should frame your recorded actual home path, for example
</home/mira> as an illustration, not a required username. The second
prints <$HOME>. Compare the first with the home path observed earlier; if it
differs unexpectedly, return to the declared setup rather than assigning HOME.
Inside double quotes, a backslash can also protect this dollar sign from
expansion. This specific form therefore prints the literal <$HOME>:
printf '<%s>\n' "\$HOME"
These are bounded examples of quoting and one existing value. They do not mean double quotes suppress all expansion or that every backslash in every context is removed.
6. Expand known filename patterns
A filename pattern is matched against names in the relevant directory.
For the unquoted patterns used here, * matches zero or more characters and
? matches exactly one character. The characters do not cross a / pathname
separator. These examples contain no slash, so matching uses the verified
current exercise directory.
Quoting the pattern characters keeps them literal instead of selecting files. Predict each resulting set of data arguments before running:
printf '<%s>\n' day?.txt
printf '<%s>\n' day*.txt
printf '<%s>\n' 'day?.txt'
printf '<%s>\n' "day?.txt"
| Typed filename portion | Result under the checked fixture and options |
|---|---|
day?.txt | Two data arguments: day1.txt and day2.txt. |
day*.txt | Three data arguments: day1.txt, day2.txt, and day notes.txt. |
'day?.txt' | One literal argument containing day?.txt. |
"day?.txt" | The same literal pattern text in one argument. |
Bash sorts matches according to its locale. The table states membership, not
a universal print order. Compare which complete values appear and how many
there are. Crucially, the matched filename day notes.txt stays one argument;
the space inside a filename produced by matching is not split into new words.
That differs from typing the two unquoted literal words earlier.

Read the arrows from typed filename text to the resulting data-argument boxes.
The command word and printf format are omitted. The two matching boxes show
the selected names as a set; their layout does not promise locale-independent
ordering. Both scenes depend on this fixture and the checked Bash settings.
An unmatched pattern is still an argument in this baseline
There are no names beginning with absent in the supplied directory. With
nullglob and failglob off, this unmatched pattern is retained literally:
printf '<%s>\n' absent*.txt
Expect <absent*.txt>, meaning one literal data argument. It is not a filename
that suddenly exists, and it is not zero arguments. Different option settings
can instead remove an unmatched pattern or produce an error; this lesson
inspects those settings and preserves them rather than switching behavior.
Verify names through a read-only file operation
The following listing uses a pattern only to inspect the two selected files.
-- belongs to ls and ends its options; Bash has already expanded the pattern
before ls receives the pathnames:
ls -ld -- day?.txt
Require records for the two numbered files. Inspect the leading-hyphen and spaced names explicitly as well:
ls -ld -- --draft.txt 'day notes.txt'
Both operands should identify their actual regular files. Quoting a leading
hyphen alone would not disable a program's option parser; the standalone --
is the relevant program-level boundary here. Neither listing changes files.
Diagnose a different argument set
| Observation | Evidence and safe response |
|---|---|
| More names match than predicted | Inspect pwd, ls -a, the pattern and matching settings. Do not narrow a deletion command by trial and error; this lesson uses patterns only for printing/reads. |
| A spaced matched filename appears in one frame | That is the expected single argument produced by filename expansion, not a split typed word. |
| A quoted pattern appears literally | Quoting prevented filename matching; compare the intended literal versus selected-name outcome. |
| Unmatched text disappears or becomes an error | The declared option assumptions may differ. Preserve settings and reconcile them before claiming the baseline result. |
<> appears | Inspect whether the command had an empty argument or no data argument. This format alone cannot distinguish them. |
| The home value differs | Read the existing value against the recorded account/home evidence; do not reassign it here. |
| A dashed filename is mistaken for an option | Check the receiving command's documented -- boundary, not only quotes. |
Independent task: combine a pattern with a literal name
Keep the same four-file fixture and unchanged shell settings. Before running anything, write the complete data-argument set you intend to supply.
- Construct one
printfinvocation with the taught format. Use a filename pattern to select the two numbered day files, then add the spaced file as one separate literal pathname argument. Exclude--draft.txt. - Predict how many data arguments that supplies. Run your printing command and compare the values, allowing for locale-dependent ordering of the matched portion. The literal argument follows that expanded portion in your line.
- Explain why the broader star pattern followed by the same literal spaced name would include that name twice rather than identify an extra file.
- Explain what changes when your numbered-file pattern is put inside either kind of quotes, and why single versus double quotes behaved differently for the existing home-value example.
You succeed when the printed values match the predicted intended arguments and you can explain which came from matching and which was supplied literally. No file change, automatic score or guessed argument count is required.
Hints
Hint 1 — use the exact-width pattern: the two numbered names have one
character between day and .txt; the spaced name has several there.
Hint 2 — keep the two mechanisms separate: leave the selecting pattern unquoted, then quote the entire literal spaced name as a separate word.
Hint 3 — use the display's conditions: there are three supplied nonempty data arguments here. The format is a separate argument and is not one of the filename results shown by the figure.
Answer and Reasoning
In the checked exercise directory, the intended printing command is:
printf '<%s>\n' day?.txt 'day notes.txt'
The unquoted pattern expands to the two numbered filenames. The quoted literal
provides one additional argument containing its internal space. There are three
filename data arguments plus the separate format argument. The matched portion
is locale-sorted, and the explicitly supplied literal follows it. The values
are day1.txt, day2.txt and day notes.txt; --draft.txt is not selected.
Using day*.txt instead would already select the spaced filename as one of
three matches. Appending the literal spaced name would therefore supply it
again, for four data arguments total. Repetition in the argument list does not
create another filesystem entry.
Quoting day?.txt with either single or double quotes supplies the literal
question-mark text instead of performing filename expansion. Both protect
that pattern, but the taught home example differs: double quotes allow the
existing $HOME value to expand while single quotes preserve $HOME as text.
The escaped dollar-sign example preserves the literal value inside double
quotes. Quote behavior must be explained for the particular syntax involved.
The unmatched example supplied literal absent*.txt under the checked defaults.
If no data arguments had been supplied, this printf format would still print
<>; it would not be a reliable empty-set detector. The combined evidence is
the source line, known names, checked settings and actual displayed values.
Cleanup after the independent task
Patterns were only for printing and read-only listings. Cleanup names all four fixture files explicitly and retains the original shell configuration. Recheck the existing shared-root and exercise entries without trailing slashes:
ls -ld ~/linux-practice
ls -ld ~/linux-practice/quote-and-expand-arguments
Require the known owned directories. Enter the exercise and check location in a separate step:
cd ~/linux-practice/quote-and-expand-arguments
pwd
Require the exact recorded exercise path before deletion. Inspect the complete inventory and each explicitly named entry:
ls -a
ls -ld -- day1.txt day2.txt 'day notes.txt' --draft.txt
Require only the four known regular files, each with one link, the ordinary owner and the supplied empty contents. Keep any unexpected or changed input instead of removing it to make the fixture look fresh.
The shown y/n responses assume English confirmations. Establish the actual
program's documented responses beforehand; stop before this operation if its
language or response convention is unclear. Only after all task and target
checks are complete, use the already taught interactive named removal:
rm -i -- day1.txt day2.txt 'day notes.txt' --draft.txt
Approve only the expected owned targets. If stopping, decline the current and
every remaining prompt; one n does not cancel later prompts. Inspect ls -a
afterward and require only . and .. before removing the directory.
Return to the shared root and inspect it before any further mutation:
cd ~/linux-practice
pwd
Require the previously recorded shared-root path. Then inspect the exercise entry itself:
ls -ld -- quote-and-expand-arguments
Only for that known owned directory with verified emptiness:
rmdir -- quote-and-expand-arguments
ls -a
The shared practice root and other lessons remain. No options, HOME,
GLOBIGNORE or profile settings were changed, so there is no settings reset
to perform.
Resume from inspected state
Recheck the ordinary account, Bash options, optional filter and exact paths.
If the existing exercise contains exactly the four known empty regular files,
inspect and reuse them. Do not run touch over an unrecognized existing file;
it would change timestamps rather than validate or clear its contents. Create
only a verified missing named input with the taught explicit touch form if
you deliberately need to repeat the fixture.
After partial cleanup, inspect the actual remaining names before continuing. Do not replace explicit targets with a pattern. Unexpected matches, links, owners, contents or settings remain conditions to reconcile, not permission for broad cleanup or shell-option changes.
Technical references
- GNU Bash 5.2-family manual — quoting, the existing home parameter, filename expansion and its settings, inspection builtins, and
printfformat reuse/missing-value behavior. - GNU coreutils manual — explicit fixture creation, file entry inspection, option boundaries and named cleanup. Use the longstanding forms shown for Noble's 9.4 family rather than assuming newer upstream features.
Use Revision to reconstruct the argument transformations and Quick Reference for the bounded patterns and checks.