Page 1 of 1

bmi (m/kg)

Posted: Mon Mar 09, 2015 5:43 pm
by machinebacon
Short script to calculate the BMI, this requires kilograms and meters (with period) to work. If you like, you can change it to work with inches and pounds. Seems weight has to be multiplied with 703 then. No idea.

Works like this:
./bmi.sh 88 1.78
Your BMI is 27.8

Code: Select all

#!/bin/bash
if [ $# -lt 2 ]; then
    echo "Usage: $0 weight height"
    exit 1
fi
weight=$1
height=$2
echo "Your BMI is $(bc <<< "scale=1; $weight / ($height * $height)")"
Of course you can add stuff:
- ask for gender
- ask for age
- compare result with BMI definitions (underweight, normal, overweight, obese, DebJoe)
- give a kcal/kJ recommendation for the next 4/8/12/24 weeks
- let it make a sandwich for you

Have fun.

Re: bmi (m/kg)

Posted: Mon Mar 09, 2015 7:14 pm
by rhowaldt
complaint: bc is not installed on Bork! by default. wtf? i thought this was a serious distro.

lovely script Jules, thanks! adapted the script to make judgment and give advice. also added interesting information to educate the user. it is now a lot bigger, and, therefore, better.

sample:

Code: Select all

[19:08:47]$ bmi-advisor 72 1.87
Your BMI (or Quetelet index) is 20.6.
This makes you: Normal

Do you agree with this judgment? [yes or no]: y
Good. We are happy you trust us. Let us give you some advice.

*** EXPERT ADVICE TIME ***
Do you feel good? [yes or no]: y
Great! Good day.
script:

Code: Select all

#!/bin/bash
if [ $# '<' 2 ]; then
    echo "Usage: $0 weight height"
    exit 1
fi
weight=$1
height=$2
bmi=$(bc <<< "scale=1; $weight / ($height * $height)")

state[1]="Very Severely Underweight"
state[2]="Severely Underweight"
state[3]="Underweight"
state[4]="Normal"
state[5]="Overweight"
state[6]="Moderately Obese (Obese Class I)"
state[7]="Severely Obese (Obese Class II)"
state[8]="Very Severely Obese (Obese Class III)"


if [ $(echo $bmi'<'15 | bc -l) -eq 1 ]; then
	poo=1
elif [ $(echo $bmi'>='15 | bc -l) -eq 1 -a $(echo $bmi'<'16 | bc -l) -eq 1 ]; then
	poo=2
elif [ $(echo $bmi'>='16 | bc -l) -eq 1 -a $(echo $bmi'<'18.5 | bc -l) -eq 1 ]; then
	poo=3
elif [ $(echo $bmi'>='18.5 | bc -l) -eq 1 -a $(echo $bmi'<'25 | bc -l) -eq 1 ]; then
	poo=4
elif [ $(echo $bmi'>='25 | bc -l) -eq 1 -a $(echo $bmi'<'30 | bc -l) -eq 1 ]; then
	poo=5
elif [ $(echo $bmi'>='30 | bc -l) -eq 1 -a $(echo $bmi'<'35 | bc -l) -eq 1 ]; then
	poo=6
elif [ $(echo $bmi'>='35 | bc -l) -eq 1 -a $(echo $bmi'<'40 | bc -l) -eq 1 ]; then
	poo=7
elif [ $(echo $bmi'>='40 | bc -l) -eq 1 ]; then
	poo=8
fi

echo "Your BMI (or Quetelet index) is $bmi."
echo "This makes you: ${state[$poo]}"
echo ""
echo -n "Do you agree with this judgment? [yes or no]: "
read yno
case $yno in

        [yY] | [yY][Ee][Ss] )
                agree=1
                ;;

        [nN] | [n|N][O|o] )
                agree=0
                ;;
        *) echo "Invalid input"
            ;;
esac

if [ $agree -eq 1 ]; then
	echo "Good. We are happy you trust us. Let us give you some advice."
	echo ""
elif [ $agree -eq 0 ]; then
	echo "You disagree with our science. Fuck you."
	exit 1
fi


echo "*** EXPERT ADVICE TIME ***"
echo -n "Do you feel good? [yes or no]: "
read yno
case $yno in

        [yY] | [yY][Ee][Ss] )
                good=1
                ;;

        [nN] | [n|N][O|o] )
                good=0
                ;;
        *) echo "Invalid input"
            ;;
esac

if [ $good -eq 1 ]; then
	echo "Great! Good day."
	exit 1
elif [ $good -eq 0 ]; then
	echo "We, the Experts, advise you to have a good look at your dietary experience to see if there is anything that might be changed to make you feel a bit better."
	exit 1
fi


Re: bmi (m/kg)

Posted: Mon Mar 09, 2015 9:13 pm
by machinebacon
Beautiful, thanks rhowaldt.

(I thought wcalc was installed instead :) )

Re: bmi (m/kg)

Posted: Tue Mar 10, 2015 3:44 am
by rust collector
Oh shit!

Umm, script works well, I am not sure if it was something I wanted to know though?

Re: bmi (m/kg)

Posted: Wed Mar 11, 2015 1:23 am
by ivanovnegro
Oh shit, wtf is this, how crazy, loving this fucking script. Awesome.

Re: bmi (m/kg)

Posted: Wed Mar 11, 2015 3:05 pm
by Dr_Chroot
^ Indeed. Another nice script, mb and rho :)

Re: bmi (m/kg)

Posted: Wed Mar 11, 2015 5:00 pm
by rhowaldt
customize it bitches! add insults, then let your mom/sister/gf try it out.