?
Solved

bash programming - displaying (real) numbers

Posted on 2003-03-06
2
Medium Priority
?
203 Views
Last Modified: 2011-09-20
Hello!
I'm having problems with bash programming - when i try to do something like:
a=3
b=5
echo div: $(($a/$b))
I get 'div: 0'.
How can i display decimals?
|bc -l? how?

TNX
0
Comment
Question by:jurij
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 150 total points
ID: 8081886
Try this:

$a=3
$b=7
$ echo "$a $b"|awk '{printf "Div: %5.5f\n",$1/$2;}'
Div: 0.42857
0
 
LVL 2

Expert Comment

by:jimbb
ID: 8086367
a=3
b=5
decimal_places=3

echo "scale=$decimal_places; $a/$b" | bc
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question