Get the App
SLTechnology News&Howtos  ›  Servers  › 

The role of linux's expr command

Shulou Source: shulou.com Published: 2022-06-02 19:50:35 09月24日 Update

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.

Tags: Character command action expression content string quotation mark space reference operation special learning for application four operations multiplication sign value position full name parameter variable meaning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS OPPO Reno Docker Microsoft