What is the expansion in Linux?

by Daniel Pham
Published: Updated:

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?

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
use echo command with simple text
Use “echo” command with simple text.

Next, we try to type the echo command with the * character.

$ echo *
use "echo" command with * character to demo expansion
Use “echo” command with * character to demo expansion.

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.


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).

0 0 votes
Article Rating
Series NavigationNext part: Example about pathname expansion in Linux »»

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.