Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The role of linux's expr command

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Today, what the editor shares with you is the role of linux's expr command. I believe many people do not know much about it. In order to make you understand better, I have summarized the following contents for you. Let's look down together. I'm sure you'll get something.

The English full name of expr command is "expression", which means expression. It acts as a counter on the command line. It is often used to find the value of expression variables in the UNIX/LINUX system. It is generally used for integer values and can also be used for strings.

Syntax format: expr [expression]

Common parameters:

Spaces separate each item\ (backslash) in front of shell specific characters "(quotation marks) enclose strings containing spaces and other special characters in quotation marks

Reference example

Calculate the string length:

[root@linuxcool ~] # expr length "this is a test"

fourteen

Grab the string:

[root@linuxcool ~] # expr substr "this is a test" 3 5

Is is

Grab the location of the first character number string:

[root@linuxcool ~] # expr index "sarasara" a

two

Integer operation:

[root@linuxcool ~] # expr 14% 9

five

[root@linuxcool] # expr 10 + 10

twenty

[root@linuxcool] # expr 1000 + 900

1900

[root@linuxcool] # expr 30 / 3 / 2

five

[root@linuxcool ~] # expr 30 * 3

Expr: Syntax error

[root@linuxcool ~] # expr 30 / * 3

ninety

Note: when using a multiplication sign, its specific meaning must be masked with a backslash. Because shell may misunderstand the meaning of showing an asterisk

Use expr to perform four operations:

[root@linuxcool] # expr\ (10 + 10\)\ * 2 + 100

The role of the expr command on linux is shared here. I hope the above content can be of some reference value to everyone and can be put into practice. If you like this article, you might as well share it for more people to see.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report