Shell script learning-4 (* assignment result)

Source: Internet
Author: User
Tags echo command

Let's take a look at the asterisk assignment:

 

[Rocrocket @ rocrocket ~] $ Myvar = *

[Rocrocket @ rocrocket ~] $ Echo $ myvar
Apache-tomcat-5.5.26.tar.gz audiodump.wav desktop documents download dwhelper educonn.tar.gz music pictures public subversion-1.4.0-29.i586.rpm subversion-server-1.4.0-29.i586.rpm templates videos

 

-- The original * will be automatically replaced with the file list in the current directory.

 

In fact, the idea above cannot let us fully understand the essence. This is a shell knowledge point. Let us know.

Shell does not replace the file name when assigning values to variables. So when you execute x = *, only an asterisk is assigned to the X variable. The actual replacement occurs in Echo $ X.

The detailed steps are as follows:

1. When x = * is executed, shell scans the command line and assigns * to X.

2. When Echo $ X is executed, shell replaces $ X *

3. Shell replaces * with the file list in the current directory.

4 shell executes the echo command to pass the file list as a parameter to it.

This is the procedure. It is not difficult to remember: "variables are not replaced by matching values. Shell replaces variables first, file names, and finally processes parameters ".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.