nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Shell scripting: How to compare float values

This is a discussion on Shell scripting: How to compare float values within the Shell scripting forums, part of the Development/Scripting category; Hi, I'm new to shell scripting. I'd able to compare two integers, however I couldn't compare 2 2 float values. ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 07-26-2007, 01:38 PM
Junior Member
User
 
Join Date: Jul 2007
My distro: Debian
Posts: 3
Rep Power: 0
chanderbio is on a distinguished road
Default Shell scripting: How to compare float values

Hi,

I'm new to shell scripting. I'd able to compare two integers, however I couldn't compare 2 2 float values. Can u please tell me how I can compare 2 float values?

For e.g to find greater value between 5.6 and 7.8...

Purnachander.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 06:46 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Use bc and pipes as follows

Code:
st=$(echo "12.6 > 15.77" | bc)
if [ $st -eq 1 ]; then # 1 == true
  echo "True"
else
  echo "False"
fi
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
need help on shell scripting rahul_sayz Shell scripting 1 12-08-2007 11:37 AM
Why are ulimit values not being set properly upon SSH (Secure Shell) login? jerry Networking, Firewalls and Security 0 06-15-2007 11:58 PM
Use float real numbers in a shell script hao Shell scripting 1 03-16-2007 02:35 AM
How can I Update the XML Tag Values using Shell Script Mithun_Kamath Shell scripting 1 01-25-2007 01:29 AM
Learning Shell Scripting ricc Shell scripting 4 08-30-2005 10:37 AM


All times are GMT +5.5. The time now is 06:55 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36