2016-04-21 13:44:40 +01:00
|
|
|
# expr
|
|
|
|
|
|
|
|
> Evaluate expressions and manipulate strings.
|
2021-04-01 16:54:26 +01:00
|
|
|
> More information: <https://www.gnu.org/software/coreutils/expr>.
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
- Get the length of a specific string:
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
`expr length "{{string}}"`
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
- Get the substring of a string with a specific length:
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
`expr substr "{{string}}" {{from}} {{length}}`
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
- Match a specific substring against an anchored pattern:
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
`expr match "{{string}}" '{{pattern}}'`
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
- Get the first char position from a specific set in a string:
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
`expr index "{{string}}" "{{chars}}"`
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
- Calculate a specific mathematic expression:
|
2016-04-21 13:44:40 +01:00
|
|
|
|
2023-02-21 09:57:06 +00:00
|
|
|
`expr {{expression1}} {{+|-|*|/|%}} {{expression2}}`
|
|
|
|
|
|
|
|
- Get the first expression if its value is non-zero and not null otherwise get the second one:
|
|
|
|
|
|
|
|
`expr {{expression1}} \| {{expression2}}`
|
|
|
|
|
|
|
|
- Get the first expression if both expressions are non-zero and not null otherwise get zero:
|
|
|
|
|
|
|
|
`expr {{expression1}} \& {{expression2}}`
|