The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conditional FTP Dastard Shell Programming and Scripting 2 06-21-2008 07:38 AM
AWK - conditional cause Rafael.Buria Shell Programming and Scripting 2 01-28-2008 01:24 PM
for i loop with conditional statements? xgringo Shell Programming and Scripting 2 12-13-2007 04:16 PM
Please help on IF statements. filthymonk Shell Programming and Scripting 4 07-18-2007 05:59 AM
Else in If Statements chapmana UNIX for Dummies Questions & Answers 8 11-30-2006 08:07 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-15-2005
cstovall cstovall is offline
Registered User
  
 

Join Date: Nov 2002
Location: Raleigh, N.C.
Posts: 78
Conditional Statements

How can I compare two decimal values within a function using Bash? Function fun2 isn't comparing the decimal values. Is there a way to do this using Bash or Korn?


#!/bin/bash
set -x


x=1
z=110



function fun1() { i=`bc << EOF 2>> /dev/null
scale=3
$x/$z
EOF`
echo $i >> /dev/null

p=`bc << EOF 2>> /dev/null
100 * $i
EOF`

s=`echo "$p" | cut -c1-3`
echo "$s%"
}


function fun2() { i=`bc << EOF 2>> /dev/null
scale=3
$x/$z
EOF`
echo $i >> /dev/null;

p=`bc << EOF 2>> /dev/null
100 * $i
EOF`

s=`echo "$p" | cut -c1-4`

if [ $s -lt "1.00" ]
then
echo "The value is less than 1.00%"
else
echo "$s%"
fi

}




if [ $x -eq $z ]
then
fun1
else
fun2
fi
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 01:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0