In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article is about the role of various parentheses in shell under linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
Single parenthesis ()
But there are two common functions of parentheses: command substitution and array initialization
Command replacement
When the $() structure is encountered, shell executes the command in parentheses and returns the result
# tmp=$ (date) # echo $tmpFri Sep 18 10:22:30 CST 2020
Initialize array
# initialize the array lnmp= (linux nginx mysql php)
Double parentheses ()
Keep in mind that there is a feature of double parentheses, that is, the parentheses should conform to the syntax of the c language, and there is no need to add the $symbol when using variable names.
There are many uses of double parentheses, which can be used as integer calculations (decimals are not supported). For example: $((3x2))
# echo $((1 / 3)) / n _ 1 / 2) echo $((n _ 1 / 7)) 10
As long as the operation extension that conforms to the syntax of c language can be written in parentheses
# echo $((3-4 > 5-1: 0)) "echo $((3-4 > 9-1: 0)) 0
Re-assign a value to the variable. Do not add the $symbol in parentheses at this time
# iTunes 1; ((iTunes +)); echo $iTory iTory 1; ((iTunes 100)); echo $iTX 100
Double parentheses are also often used in for loops
For ((iTuno Tinci 2) then. Fi
It can also be used as an array subscript:
# echo ${lnmp [1]} nginx
Used in a rule to represent a range
[0-9] means the number 0-9 is fine.
Both parentheses
Like single parentheses, both parentheses are also used in condition judgment, but it is more general than single square brackets. Here is an example:
Change [a > b] & & [a > 0] or [a > b-a > 0] to double parentheses [[a > b & & a > 0]]
Single curly braces {}
Curly braces expand. (globbing) will extend the file name in curly braces. In curly braces, no white space is allowed unless the white space is referenced or escaped.
For example, typing the command rm-f {1jie 2} .txt will delete the 1.txt and 2.txt files.
In single curly braces.. The role of
Two dots here mean a range. such as
Echo {1... 10} # will print 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Curly braces are also commonly used in shell scripts for code blocks.
In addition to the first time, single curly braces can also be used for the replacement and deletion of variable contents and for testing variable contents, giving a common example. We often determine whether a variable exists or not, and if not, set a new value for the variable.
Val=$ {n1:-test}
The above code indicates that if the N1 variable does not exist or is empty, the value of the val variable is set to test, otherwise the Val value is the value of the N1 variable
Thank you for reading! The role of various parentheses in shell under linux is shared here. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.