Brief Introduction of bash functions-general Linux technology-Linux programming and kernel information. The following is a detailed description. Bash provides seven types of expansion functions, namely (according to the expanded execution order): parentheses expand, wave number expand, variable expand, arithmetic expand, command replace, Word Segmentation and path name expand.
Parentheses
Brackets can be expanded in two forms:
A {B, c, d} e --> abe ace ade
A {B .. d} e --> abe ace ade
Brackets can also be nested:
1 {aa, B {c, d} 2 --> 1aa2 1bc2 1bd2
Wave expand
After the wave number is expanded, it is equivalent to specifying the user's main directory path (assuming that the current user is a user)
~ -->/Home/user
~ Root -->/root
Variable Expansion
Assume there is variable x:
X = "Hello World"
So
$ X --> Hello World
$ {X} --> Hello World
$ Xasdf --> Replace with the value of the variable named xasdf. leave it blank if it is not defined.
$ {X} asdf --> Hello Worldasdf
Arithmetic Expansion
The general form of arithmetic expansion:
$ (Expression ))
You can perform mathematical operations in arithmetic expansion:
$(100 + 9) --> 109
Command replacement
The general form of command replacement:
$ (Cmd)
'Cmd'
For example:
$ (Echo asdf) --> asdf
Word Segmentation
If Variable Expansion, arithmetic expansion, and command replacement are not enclosed in double quotation marks, bash splits the variable:
X = "Hello World", expand and get two words: "Hello", "World"
$ X --> Hello World
Expand path name
Used to match existing file names in the file system
* Match any string, including an empty string
? Match any character
[...] Match any character in []
[!...]
[^...] Does not match [!], Any character in [^ ...]
Process replacement
Process replacement requires the system to support fifo files
The general format is:
> (List) is replaced by the standard input file name of the list. Writing data to the file allows the list to be read from the standard input.
<(List) is replaced by the standard output file name of the list. You can read this file to get the standard output of the list.
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.