expr is a command in the Linux system, can be used for the operation of computer strings of integer values, then what is the purpose of the expr command? The following small series will give you a detailed introduction to the use of the expr command on Linux, let's learn together.
wordlength
# expr length & ldquo; this is a test & rdquo;
14
seeking quotient digital
# expr 14 % 9
5
Grab a string from a location
# expr substr “this is a test” 3 5
Is is
number string only the first character
# expr index “testforthegame” e
2
String reappears
quote thisisatestformela
thisisatestformela
The expr command is a manual command line counter for evaluating the value of an expression variable under UNIX/LINUX, generally for integer values, or for use. In the string.
– The format is:
expr Expression (the command reads the Expression parameter, calculates its value, and then writes the result to standard output)
– Rules:
Separate each item with a space;
Put a \\ (backslash) in front of a shell-specific character;
contains spaces and other special characters Strings should be enclosed in quotation marks
Expr usage examples:
(1) Calculate string length
# expr length “this is a test”
14
(2) Grab Strings
# expr substr “this is a test” 3 5
is is
(3) Grab the position where the first character string appears
# expr index “sarasara” a
2
(4) The string reappears < Br>
# expr quote sara
sara
(5) integer arithmetic
# expr 14 % 9
5
# expr 10 + 10
20
# expr 1000 + 900
1900
# expr 30 /3 /2
5
# expr 30 \\* 3 (When using multiplication , you must use a backslash to block its specific meaning. Because the shell may misunderstand the meaning of the asterisk)
90
# expr 30 * 3
expr: Syntax error
(6) Incremental Count
Description: expr is used for incremental calculation in loops. First initialize the variable to 0, then add 1 to the loop value. The use of backquotes is replaced by commands.
》 LOOP=0
》 LOOP=`expr $LOOP + 1`
(7) Numerical Test
Description: Test a number with expr . If you try to calculate a non-integer, an error is returned.
# rr=3.4
# expr $rr + 1
expr: non-numeric argument
# rr=5
# expr $rr + 1
6
(8) Pattern Matching
Description: expr also has a pattern matching function. You can use expr to calculate the number of characters in a string by specifying a colon option. .* means that any character is repeated 0 or more times.
# VALUE=account.doc
# expr $VALUE : ‘.*’
8
String matching can be used in expr Operation, here use the schema to extract the .doc file attachment name.
$expr $VALUE : ‘\\(.*\\).doc’
account
The above is the usage of the Linux expr command, we can use the expr command Perform digital business search, true reproduction of strings, grab strings, etc., which is equivalent to the command line calculator.
The installation of Ubuntu software can be easily installed through the software ce
Nginx log files how to clean up, will become bigger and bigger, affecting the opera
In the Ubuntu system, it is best to check the integrity of the downloaded files (se
When there is still a lot of space on the Linux system hard disk, we can use the fd
Linux finds the way to replace text content by command.
Tips for setting up IPv4 in Ubuntu system
How to use the Linux system Docker command
Linux automatic installation operation example
How to import files from a Docker container to the host
A brief introduction to the Linux signal mechanism
The difference between Linux and Windows systems
Linux uses sonar to get the number of violations and lines of code
RHEL6 changes the name of the asm disk by udev.
How does Win10 stop running services to reduce the occupation of hardware resources?
Win7 web game can not open how to do
How to implement VHD startup under Windows 7
Tips for restoring file open mode
8 practical small software: help you get back to Windows 8 start menu