1

I have a book that says that the output of the command echo * is the line that follows below. I can't find why it outputs that. Please help.

$ echo *
local.cshrc local.login local.profile
1
  • 2
    Bash globbing and filename expansion Mar 18, 2017 at 10:58

2 Answers 2

4

* is shell special character (glob match) that matches the names of files and directories in the current directory.

$ ls *

This will list all files and directories in current directory. So, in your case '*' returns and 'echo' prints them on the console. Try this to confirm:

$ x=*
$ echo $x 
2
  • ls * is slightly different from echo *; mkdir p; touch p/j
    – Jeff Schaller
    Mar 18, 2017 at 14:43
  • Agree. ls * will also display the content of first level subdirectories.
    – Sharad
    Mar 18, 2017 at 17:42
1

You are using a wildcard - * which is used with globbing and file-expansion.

The referenced link above describes this further:

Standard wildcards (also known as globbing patterns) are used by various command-line utilities to work with multiple files. For more information on standard wildcards (globbing patterns) refer to the manual page by typing:

and

* (asterisk) this can represent any number of characters (including zero, in other words, zero or more characters). If you specified a "cd*" it would use "cda", "cdrom", "cdrecord" and anything that starts with “cd” also including “cd” itself. "m*l" could by mill, mull, ml, and anything that starts with an m and ends with an l.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .