mardi 24 février 2015

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


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:



#!/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


Aucun commentaire:

Enregistrer un commentaire