Why does 'echo *' give different results than 'ls *'?

For example, if you are in home directory and type ls *, you will have all the directories listed, and below the name of the listed directory, the files that it contains. On the other hand, if you type echo * the command will list just the directories, and not the directories and content that they have. Why is that?

1

1 Answer

In both cases the * gets expanded by the shell.

echo than just prints the parameters resulting from the expansion.

ls checks for every parameter if it is a directory and lists its contents if it is one.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like