bmi (m/kg)

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

bmi (m/kg)

Unread post by machinebacon » Mon Mar 09, 2015 5:43 pm

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.
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: bmi (m/kg)

Unread post by rhowaldt » Mon Mar 09, 2015 7:14 pm

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

All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: bmi (m/kg)

Unread post by machinebacon » Mon Mar 09, 2015 9:13 pm

Beautiful, thanks rhowaldt.

(I thought wcalc was installed instead :) )
..gnutella..

User avatar
rust collector
Motörhead
Posts: 535
Joined: Mon Jan 13, 2014 3:56 pm
Location: no_nb

Re: bmi (m/kg)

Unread post by rust collector » Tue Mar 10, 2015 3:44 am

Oh shit!

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

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: bmi (m/kg)

Unread post by ivanovnegro » Wed Mar 11, 2015 1:23 am

Oh shit, wtf is this, how crazy, loving this fucking script. Awesome.

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: bmi (m/kg)

Unread post by Dr_Chroot » Wed Mar 11, 2015 3:05 pm

^ Indeed. Another nice script, mb and rho :)
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: bmi (m/kg)

Unread post by rhowaldt » Wed Mar 11, 2015 5:00 pm

customize it bitches! add insults, then let your mom/sister/gf try it out.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

Post Reply