What happens when you type ls *.c ?

ls command in bash

How does the shell interpret the command just passed ?

  1. It will split the command in 2 tokens, ls and *.c
  2. It will expand the variables, here *.c . the use of * variable means the shell will look for filenames with the pattern “name ending by .c in current directory”
  3. Then it substitutes this pattern by what it finds, in the example: file.c
  4. The shell moves on to ls, it first looks if ls is an alias, and if it is it loops until it finds what ls really stands for.
  5. Assuming ls just meant use ls program, the the shell looks if it is a shell built-in.
  6. It is not, so the shell follows the directory listed in the PATH variable. This variable lists all the directories containing the executables on the computer.
  7. It should find ls in /usr/bin. Then it executes it. Since there are no options, it will lists what the second token is feeding it. In the example file.c.
  8. The shell will prompt us for another command. In order to do that it will use the PS1 variable which defines what the prompt should look like.

END.