Skip to content

Absolute Value

Print the absolute value of an integer argument, stripping a leading minus so downstream scripts always see a non-negative number.

Language: Shell

Added on: 18th August 2026

abs() {
  (( $1 < 0 )) && echo "$(( $1 * -1 ))" || echo "$1"
}