![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|