LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   URGENT NEED: floatting numbers in BASH shell (https://www.linuxquestions.org/questions/programming-9/urgent-need-floatting-numbers-in-bash-shell-153885/)

grueugene 03-05-2004 01:44 PM

URGENT NEED: floatting numbers in BASH shell
 
I have a following piece of code:
..............
ROOMNIGHTS=`expr $ROOMCOUNT "*" $DAYS` && debug "ROOMNIGHTS=$ROOMNIGHTS"

# occupancy rate
BCCMD="scale=2; $OCCNIGHTS / $ROOMNIGHTS" && debug "BCCMD=$BCCMD"

OCCRATE=`echo $BCCMD | bc` && debug "OCCRATE=$OCCRATE"

echo "last $DAYS days occupancy for $LOCNAME was $OCCRATE"
..................
when I execute it it gives me next output:
./occ_rate.sh: bc: command not found

last 4 days occupancy for vmware was


What should I use instead of bc to get floating number as a result of division.

Thank's

Eugene

mfeat 03-05-2004 02:01 PM

echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'

grueugene 03-05-2004 02:21 PM

Thank's a Lot
 
Thank's a lot.

It worked!!!

Eugene.

grueugene 03-11-2004 03:55 PM

Hi again.

I may need your help again with the same script:

I have the following piece of script:

DAYS=`echo $SQLCMD| $SQLPRG | tail -n 1` && debug "DAYS=$DAYS"

ROOMNIGHTS=`expr $ROOMCOUNT "*" $DAYS` && debug "ROOMNIGHTS=$ROOMNIGHTS"

OCCRATE= echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'

echo "last $DAYS days occupancy for $LOCNAME was $OCCRATE"

--------------------------------
My output is following:

[root@kcapp bin]# ./occ_rate.sh
1.15
last 10 days occupancy for vmware was

Why $OCCRATE value is not displayed and how to display it?

Thank's

Eugene.

jim mcnamara 03-11-2004 04:30 PM

try
Code:

OCCRATE= `echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'`

mfeat 03-12-2004 09:25 AM

yes, as jim has shown, add the backquotes but may also need to remove the space after
the "="


All times are GMT -5. The time now is 07:55 AM.