In this article, what will we learn about expansion in Linux? What does it do when we type the command on the terminal?
Throughout this series, we only use a single echo
command. This command is quite simple and probably everyone knows, it will print out the text content that we type from the keyboard.
What is the expansion?
Table of Contents
Every time we type the command and press the enter key, bash will do some processing on the text before actually executing the command we typed.
Maybe, you saw this in the previous examples but didn’t notice. For example, characters *
for example. When we type echo *
bash has processed this *
before executing the echo command.
This processing is expansion.
Example of expansion
You know, the echo command is a builtin shell, it’s very simple. For example:
$ echo My name is Daniel
Next, we try to type the echo
command with the *
character.
$ echo *
Recommended Reading: Get help for shell builtins with help command
You can see the result in the image above, why the echo
command does not print the *
character on the screen. Instead, it prints a list of files in the directory.
We will return a term that is wildcard
, you know, the character *
here represents any character in the filename. But in the echo
command there is no mention of this.
So what happened?
Simply explained, the shell has expanded the *
character to something else (here, it has expanded the *
character to the names of the files and subdirectories present in the current directory) before it executes the echo
command.
Conclusion
For the small example in the article, you can already grasp expansion in linux. Each time you type a command, it will process the text before it sends the command to the shell to execute. In the next article, we will learn more about expansion.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).