Compute integers and run basic string routines directly in shell scripts. 12.03.2026 | reading time: 2 min Want to add two variables, measure a string or test equality in a shell script? The POSIX `expr` utility evaluates simple integer arithmetic and offers basic string functions, making it a compact tool for quick calculations and checks right from the command line. Quick examples Try these on the shell: ```expr 5 + 3\n# output: 8\n\n# multiplication needs escape\nexpr 6 \* 7\n# output: 42\n\n# variables\na=4; b=5; expr $a + $b\n# output: 9\n\n# string length and substring\nexpr length \"hello\"\n# output: 5\nexpr substr \"hello\" 2 3\n# output: ell\n\n# comparison\nexpr 5 = 5\n# output: 1\nexpr 5 = 6\n# output: 0``` Gotchas and tips Use `expr` for portable, small expressions but remember it does integer arithmetic only and many shell metacharacters must be escaped (for example, escape `*` and redirection symbols); when performance or floating point is needed, prefer shell arithmetic or other tools. Practical uses Embed `expr` in short scripts to compute offsets, extract substrings, test numeric equality or measure lengths when you want a POSIX-compatible dependency and do not need the features of larger utilities. Alternatives to try For more power or different needs use shell arithmetic with `$(())` for speed and readability, `bc` for floating point math and `awk` for complex text and numeric processing inside pipelines. Next steps Practice transforming small scripts from `expr` to shell arithmetic and `awk`, then deepen system knowledge and consider formal certification with CompTIA Linux+ or LPIC-1 exam preparation at bitsandbytes.academy to validate skills. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting troubleshooting