What is the expansion in Linux?

Share this post to your friends !

WriteBash - 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 Danie
what-is-the-expansion-in-linux-01 What is the expansion in Linux?
Use “echo” command with simple text.

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

$ echo *
what-is-the-expansion-in-linux-02 What is the expansion in Linux?
Use “echo” command with * character to demo expansion.

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.

Continue reading the seriesNext part: Example about pathname expansion in Linux »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.