Command line tips: how to extend parameters using braces

Source: Internet
Author: User
We often encounter this problem when using Linux. for example, execute the command $ cpetcaptsourceslistetcaptsourceslistbak here.

We often encounter such a problem when using Linux, for example, executing a command

$ Cp/etc/apt/sources. list/etc/apt/sources. list. bak

There is a problem here. the words/etc/apt/sources are the same. why do I need to repeat them twice? This is a little short. if the directory is deeper, it will take a lot of effort. it is similar to the above example: back up a file and rename a file, or to create a link, perform similar operations and repeat the same path. it is generally wise to first cd to that directory and then perform operations under that directory, after the cd is complete, it will be difficult to do so. Is there any solution without leaving the house? The answer is yes.

Bash has a function called braces extension. parameters enclosed by braces, separated by commas, are extended to multiple independent parameters. in this case, you must be disconnected, the example of the backup file above can be written:

$ Cp/etc/apt/sources. {list, list. bak}

Shell automatically expands the following parameters into two during the interpretation, and then becomes the same complete command as the above, thus achieving the operation without leaving the house, the previous directory strings only need to be typed once, and the cd is skipped.

In fact, this command can be simplified, and the list can also be used in the past. I have been thinking about what is used to represent the blank. In fact, nothing needs to be written.

$ Cp/etc/apt/sources. list {,. bak}

In this way, there is nothing before the comma, so the parameter remains unchanged, and the extension after the comma remains unchanged.

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.