scripts

shell scripts
git clone git://git.bitsmanent.org/scripts
Log | Files | Refs | README

commit 46df1229ad52fb5165eb60844bd500db31350534
parent 70f35667fac7925349284e3a9a585eaaf3f306e6
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Tue, 24 Nov 2015 23:33:06 +0100

[sober] Handle wrong inputs.

Diffstat:
Msrc/sober | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/sober b/src/sober @@ -23,9 +23,9 @@ check() { sum="$(echo "${n1}+${n2}" | bc)" printf "How much is %d + %d? " "$n1" "$n2" read r - if [ "$r" -ne "$sum" ]; then - return 1 - fi + nan="$(echo "$r" | grep -c '[^0-9]')" + [ "$nan" -eq 1 ] && return 1 + [ "$r" -ne "$sum" ] && return 1 return 0 }