Sample Header Ad - 728x90

Is there a unix command that gives the minimum/maximum of two numbers?

75 votes
12 answers
123868 views
I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, simple and (I think) common use case. My script which finds the **minimum** of two numbers: #!/bin/bash # $1 limit [ -z "$1" ] && { echo "Needs a limit as first argument." >&2; exit 1; } read number if [ "$number" -gt "$1" ]; then echo "$1" else echo "$number" fi
Asked by Minix (6065 rep)
Feb 24, 2015, 07:09 PM
Last activity: Feb 21, 2023, 03:21 AM