-1

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 ? enter image description here

  • 4
    Please don't post screenshots of text. Copy the text here and use code formatting instead: https://unix.stackexchange.com/editing-help#code – muru Jun 18 '23 at 12:48
  • 4
    It has nothing to do with the terminal and everything with the shell. You need to get familiar with the behavior of your shell (zsh for you, which behaves differently here than the more standard bash), 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 with zsh, I'm only familiar with bash which works differently here. – egmont Jun 18 '23 at 19:21

1 Answers1

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.

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