If I type *
in the terminal, it is an alias for Desktop. But if I define a variable x
and set it to *
, it is not treated as such. When are certain characters treated as strings and when as operators ?
Asked
Active
Viewed 77 times
-1

Stéphane Chazelas
- 544,893
1 Answers
4
Your shell expands *
to the names of all files (except names that begin with ".
") in the current directory via a mechanism called Filename Generation also known as globbing or Pathname Expansion.
In your case, "Desktop
" was the first entry.
Look at echo *
, or ls
.

Stéphane Chazelas
- 544,893

waltinator
- 4,865
-
And for that glob expansion of happen upon parameter expansion, that is for the contents of
$x
to be considered a pattern (and it to be expanded to the matching file via filename generation when in list contexts), you need$~x
or${~x}
while a few other shells including bash do it always for any unquoted expansion which could be considered as a bug. – Stéphane Chazelas Jun 19 '23 at 16:09
zsh
for you, which behaves differently here than the more standardbash
), around the keywords patterns, wildcards, globbing, expansion etc. in order to understand what it does when it sees a*
. Sorry but I can't give an exact explanation as I'm not familiar withzsh
, I'm only familiar withbash
which works differently here. – egmont Jun 18 '23 at 19:21