EXPR(1)

πŸ“¦
version 9.10 Β· 5 versions
, in ubuntu stonking

πŸ’– NAME

expr β€” evaluate expressions ✨


πŸ¦‹ SYNOPSIS

expr EXPRESSION
expr OPTION

🌸 DESCRIPTION

  • --help β€” display this help and exit
  • --version β€” output version information and exit

Bestie, here's the whole vibe: expr prints the value of EXPRESSION to standard output. That's it. That's the job. πŸ‘‘

And here's the key tea β€” the blank lines in the list below separate increasing precedence groups. So like, stuff higher up in the list binds looser, stuff lower down binds tighter. Lowkey important. EXPRESSION can be any of these:

🫢 Group one β€” |

  • ARG1 | ARG2 β€” gives you ARG1, but only if ARG1 is neither null nor 0. Otherwise? You get ARG2. Simple as that.

πŸ’… Group two β€” &

  • ARG1 & ARG2 β€” gives you ARG1 if neither argument is null or 0. If either one is null or 0, you get 0. No cap.

πŸŽ€ Group three β€” the comparisons

  • ARG1 < ARG2 β€” ARG1 is less than ARG2
  • ARG1 <= ARG2 β€” ARG1 is less than or equal to ARG2
  • ARG1 = ARG2 β€” ARG1 is equal to ARG2
  • ARG1 != ARG2 β€” ARG1 is unequal to ARG2
  • ARG1 >= ARG2 β€” ARG1 is greater than or equal to ARG2
  • ARG1 > ARG2 β€” ARG1 is greater than ARG2

✨ Group four β€” the plus/minus era

  • ARG1 + ARG2 β€” arithmetic sum of ARG1 and ARG2
  • ARG1 - ARG2 β€” arithmetic difference of ARG1 and ARG2

πŸ”₯ Group five β€” the times/divide era

  • ARG1 * ARG2 β€” arithmetic product of ARG1 and ARG2
  • ARG1 / ARG2 β€” arithmetic quotient of ARG1 divided by ARG2
  • ARG1 % ARG2 β€” arithmetic remainder of ARG1 divided by ARG2

🌈 Group six β€” pattern matching era

  • STRING : REGEXP β€” anchored pattern match of REGEXP in STRING. It's giving "find it, but anchored". 😌

🧚 Group seven β€” the lil function words

  • match STRING REGEXP β€” same thing as STRING : REGEXP, just spelled out
  • substr STRING POS LENGTH β€” substring of STRING, and POS is counted from 1 (not zero, bestie, this is not an array πŸ’€)
  • index STRING CHARS β€” index in STRING where any CHARS is found, or 0 if none of them show up
  • length STRING β€” length of STRING

πŸ‘‘ Group eight β€” the special ones

  • + TOKEN β€” interpret TOKEN as a string, even if it is a keyword like 'match' or an operator like '/'. This is your escape hatch when expr is being too clever for its own good.
  • ( EXPRESSION ) β€” value of EXPRESSION. Classic. Main character energy.

⚠️ Beware, bestie: many operators need to be escaped or quoted for shells. Your shell will absolutely eat your |, &, <, >, *, (, ) and ; if you don't wrap them up. Protect them. 🫢

Comparisons are arithmetic if both ARGs are numbers, else lexicographical. So 10 < 9 and 10 < 9 can literally be different answers depending on whether those are numbers or plain old strings. iykyk. 😭

Pattern matches return the string matched between \( and \), or null. And if \( and \) are not used, they return the number of characters matched, or 0.


πŸ‘€ EXIT STATUS

  • 0 β€” EXPRESSION is neither null nor 0 πŸ’–
  • 1 β€” EXPRESSION is null or 0 πŸ™ˆ
  • 2 β€” EXPRESSION is syntactically invalid πŸ’€
  • 3 β€” an error occurred 😭

✍️ AUTHOR

Written by Mike Parker, James Youngman, and Paul Eggert. Legends, honestly. πŸ’…


πŸ› REPORTING BUGS


πŸ”— SEE ALSO

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.


okay that's the whole page πŸŽ€ this was GNU coreutils 9.10, dated August 2026, and honestly? she ate. go forth and expr, bestie πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from