Shell is: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
In the current working directory, there are two files:
- a file named
abc.txt
- a file named
'a'bc.txt
(created withtouch \'a\'bc.txt
)
I run the following command:
echo 'a'*
The output is:
abc.txt
The GNU bash manual specifies that quote removal is processed AFTER pathname expansion.
Therefore, I expected this command to match 'a'bc.txt
but NOT to match abc.txt
. !
I expected the above command to proceed as follows:
- at the pathname expansion stage, try to match any file with a filename
that starts with
'a'
('a'
taken as a literal string), and THUS match'a'bc.txt
- at the quote removal stage, remove the single quotes
'
in'a'
without impacting the results of the pathname expansion that took place at the previous step.
There's obviously something I don't understand here.
I could NOT find any documentation or answers to this specific question.
echo 'a'*
, even before the quote removal stage, the shell doesn't see the quotes as literal single quote characters. The quoted string'a'
is one character long, not three. To get literal single quotes, you have to quote them or escape them."'a'"*
and"'"a"'"*
both match: the difference is that the first contains a literala
, but the second would expand thea
if this was a wildcard like?
or*
.