See the world from the Shell's eyes

Source: Internet
Author: User
Tags arithmetic arithmetic operators parent directory

(character) Expand
each time you enter a command, and then pressEnterkey, inBashbefore you execute your command,Bashwill be on the input
The character completes several steps of processing. We already know two or three cases, how a simple sequence of characters, such as"*",the
shell shell
echo command. echo is a shell internal command to complete the very simple thought. It prints the text parameter of its

So what just happened? Why echo do not print "*" wildcard, this "*" character means matching any character in the file name, but in the original discussion we did not
know shell How to achieve this function. The simplest answer is shell "*" expands into something else (in this
case, the name of the file under the current working directory), in echo before the command is executed. When the ENTER key is pressed,
shell echo command will never find
" * ", Just spread it out as a result. Knowing this, we can see echo

Path name expansion
This wildcard work mechanism is called path name expansion. If we try the techniques used in the previous chapters, we
Will see that they are really going to unfold the characters. Given a home directory, it looks like this:

to view a directory outside the home directory:

hidden file path name expansion
as we know, the filename that starts with the dot character is a hidden file. Path name expansion also respects this
behavior. To unfold like this:
Echo *
hidden files are not displayed
If expand mode starts with a dot, we can include hidden files in the expand Mode, and
hidden files may appear in the first place, just like this:
Echo. *
it's almost working. However, if we examine the output carefully, we will see the name
"."and the".."also appear in the results. Because these names refer to the current working directory and its parent directory, use this
mode may produce incorrect results. We can see the result if we try this life
Order:
ls-d. *| Less
in order to properly complete the path name expansion in this case, we should employ a more precise pattern.

Ls-d. [!.]? *
This pattern expands to a filename, each file name starts with a dot, the second character does not contain a dot, and the The
contains at least one character, and the character immediately follows any number of characters. This will list most of the
hidden files (but will still not contain filenames that start with multiple dots) this with < Span style= "font-size:18pt" >-a options ("almost
" Span style= "font-size:18pt") ls command to provide a correct list of hidden files:
ls-a

positive Then the expression of something is explained in the following essay.

wavy line expand
Maybe you from us to cd In the introduction of the command, in retrospect, the wavy line character (" ~ word, it expands to the specified user's home directory name, or the current user's main
directory if no user name is specified:

Arithmetic expression expansion
Shell allows an arithmetic expression to be executed by expansion. This allows us to use the shell hint as a calculator:

(in parentheses above) an expression is an arithmetic expression that consists of numeric and arithmetic operators.
An arithmetic expression supports only integers (all numbers, without decimal points), but can perform many different operations. Here is
Some of the operators it supports:

curly braces unfold
Perhaps the strangest unfolding is curly braces. It allows you to create multiple texts from a pattern that contains curly braces.
this string. This is an example:

The curly brace expansion pattern may contain an initial part called a header, and an end part is called a postscript. Curly Brace Expression
itself may contain a comma-separated list of strings, or a series of integers, or a single string. This mode
embedded whitespace may not be included. This example uses a series of integers:

So what's good about it? The most common application is to create a series of files or directory listings. For example, if I
They are photographers and have lots of photos. We want to organize these photos in chronological order. First, we will create a series of
column with numeric value The " year-month " form of the named directory. In this way, the directory names are sorted chronologically. We can key
into the entire directory list, but the workload is too large and error-prone. Instead, we can do this:

See the world from the Shell's eyes

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.