expr

Evaluate expressions and manipulate strings. More information: <https://www.gnu.org/software/coreutils/expr>.

Install

All systems
curl cmd.cat/expr.sh
Debian Debian
apt-get install coreutils
Ubuntu
apt-get install coreutils
Alpine
apk add coreutils
Arch Arch Linux
pacman -S coreutils
image/svg+xml Kali Linux
apt-get install coreutils
CentOS
yum install coreutils
Fedora
dnf install coreutils
Windows (WSL2)
sudo apt-get update sudo apt-get install coreutils
OS X
brew install coreutils
Raspbian
apt-get install coreutils
Docker
docker run cmd.cat/expr expr powered by Commando

Evaluate expressions and manipulate strings. More information: <https://www.gnu.org/software/coreutils/expr>.

  • Get string length:
    expr length string
  • Evaluate logical or math expression with an operator ('+', '-', '*', '&', '|', etc.). Special symbols should be escaped:
    expr first_argument operator second_argument
  • Get position of the first character in 'string' that matches 'substring':
    echo $(expr index string substring)
  • Extract part of the string:
    echo $(expr substr string position_to_start number_of_characters
  • Extract part of the string which matches a regular expression:
    echo $(expr string : '\(regular_expression\)')

© tl;dr; authors and contributors