Tag: $ {} ''$ () Shell
$ (), ''For command replacement
$ {} Is used to replace variables (the following content is from shell 13)
(1). Definition of Variables
$ A=B $ echo $AB
When executing this command, the AB is regarded as a variable rather than the connection between the variable $ A and the letter B.
$ A=B $ echo ${A}B
After the command is executed, the following output is: bb
(2). Special functions are helpful for string processing.
First, define the variable file =/dir1/dir2/dir3/my.file.txt. The following command gets different values.
Extract Based on characters in the string: # And %
$ {File # */}: remove the first "/" and Its left string->/dir1/dir2/dir3/my.file.txt
$ {File ### */}: remove the last "/" and Its left string-> my.file.txt
$ {File %/*}: remove the last "/" and Its right string->/dir1/dir2/dir3
$ {File %/*}: remove the first "/" and Its right string-> Null Value
Extract specified characters in length at a specified position
String replacement
Calculate the length of the variable value: $ {# Var}
(3) array-related
3. $ () is used for calculation.
$ a=5;b=7 $ echo $((a+b)) 12
4. () You can redefine the variable value.
A = 5; (A ++) You can redefine $ A as 6
This article is from the "Linux" blog, please be sure to keep this source http://4983206.blog.51cto.com/4973206/1436474