Basic question on "echo"

what happens when I echo asterisk?

echo asterisk
asterisk
2 Likes

If you mean echo *

Then it's actually the shell that's doing it, not echo. It happens before the command is run. * is a wildcard which expands to all files in the current directory. It will happen with any command. It will not necessarily do anything sensible with every command, of course... it just dumps in filenames as arguments.

It should be added that if there are many files in the current directory, then the command to be executed (echo in this case) may be too long and throw an error.

In practice, in every POSIX shell echo is a shell builtin, for which this limit does not apply:

$ echo * | wc -w
  210000
$ /bin/echo * | wc -w
-bash: /bin/echo: Arg list too long
       0
$ type echo
echo is a shell builtin
$ type /bin/echo
/bin/echo is /bin/echo
1 Like

All of the discussion so far has ignored a couple of other possible problems... The behavior of echo varies from shell to shell and from system to system and even when using the same version of the same shell it may vary when it is installed on different systems whenever the first argument given to echo starts with a hyphen and whenever any argument given to echo contains a backslash character.

We still have no idea whether ithenr00 is asking about the command echo asterisk or echo * . If the latter is the question, then what is it about filename expansion that needs to be explained? And, what files are in the directory where this command is being executed?