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 |
echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'
|
Thank's a Lot
Thank's a lot.
It worked!!! Eugene. |
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. |
try
Code:
OCCRATE= `echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'` |
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. |