LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2004, 01:44 PM   #1
grueugene
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Rep: Reputation: 0
Question 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
 
Old 03-05-2004, 02:01 PM   #2
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'
 
Old 03-05-2004, 02:21 PM   #3
grueugene
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Thumbs up Thank's a Lot

Thank's a lot.

It worked!!!

Eugene.
 
Old 03-11-2004, 03:55 PM   #4
grueugene
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 03-11-2004, 04:30 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
try
Code:
OCCRATE= `echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'`
 
Old 03-12-2004, 09:25 AM   #6
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Decimal numbers in bash script variables? Massif Programming 3 11-07-2005 09:01 PM
Shell scripting - Random numbers within a range felixc Linux - Newbie 2 10-09-2005 05:41 PM
How to use decimal numbers in in shell scripts a1ex_007 Programming 6 03-11-2005 09:05 AM
Shell scripting - Adding many numbers in an array Stingreen Linux - General 2 10-25-2004 05:25 PM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 09:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration