Conditional Statements


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conditional Statements
# 1  
Old 05-15-2005
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
# 2  
Old 05-15-2005
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python Conditional Statements Based on Success of Last Command

In shell scripting, I can create a conditional statement based on the success or failure (exit status)of a command such as: pinger() { ping -c 2 $remote_host >/dev/null 2>&1 ping_stat=$? } pinger if ]; then echo "blahblahblah" exit 0 fi how is this done using Python using... (3 Replies)
Discussion started by: metallica1973
3 Replies

2. Shell Programming and Scripting

Too many if statements..

Hello. I am new here and new to scripting. I used to have a very basic script that worked for simple backup/restore of files. I have expanded it and well... I have ended up with a complete mess. It still backs up and restores but there is so many issues that stem from the many if statements I... (3 Replies)
Discussion started by: gameinn
3 Replies

3. UNIX for Dummies Questions & Answers

Conditional execution of statements

Hi , I have a script which has multiple awk and sed commands like below. First one :- find /root/src/ -name "*csv" -size 0 -exec rm {} \; Second one: - ls *SRE*.txt > SRT_TRAN.dat rm *asr*.txt Third one :- find /root/src/ -name '*.csv' | while read FILENAME ; do awk... (2 Replies)
Discussion started by: shruthidwh
2 Replies

4. Shell Programming and Scripting

How to use awk or nawk by using Conditional Statements

Hi Guys! Anybody know how can I use a nawk or awk on a script and printing the NAME, SECTION (must be 410 or 411 or 414) and TOTAL COST of CLASS 1 and 3 combined must be greater than 50. See below desired output file. input.txt: NAME,CLASS,COST,SECTION JOHN,1,10,410 JOHN,2,20,410... (2 Replies)
Discussion started by: pinpe
2 Replies

5. UNIX for Dummies Questions & Answers

Help with For Statements

Hi, I am trying to write a for statement that will allow for the ps, who, finger, and date commands to run. Can anyone help? I use Putty. (22 Replies)
Discussion started by: lexydoll87
22 Replies

6. Shell Programming and Scripting

HELP!! if statements

I am kind of new in Unix and i have to make a menu. I want to put an if statement in the menu. you should enter the filename and it goes to that file. How do i do this? (1 Reply)
Discussion started by: trob
1 Replies

7. Shell Programming and Scripting

for i loop with conditional statements?

New to scripting in general, so patience plz. If I ask a stupid question or don't get it, I thank you for your kindness in advance. That said, did a for i loops checks to see if a PB* file is there but I need to know two things before I copy the file. I need to know if the file's create date... (2 Replies)
Discussion started by: xgringo
2 Replies

8. Shell Programming and Scripting

Please help on IF statements.

I had different problem scenarios with IF statement. Can any expert please enlighten me on the difference with these scenarios. Thank you. 1st Scenario: testdate=`date +%Y%m` test=`cat /var/log/database0.$testdate*.log | grep "Errors found during processing" | tail -10` if then ... (4 Replies)
Discussion started by: filthymonk
4 Replies

9. UNIX for Dummies Questions & Answers

Else in If Statements

Sorry to be a pain, but how does the else work in the if statements? Ive been making scripts with if statements but i cant get the else statements working. Can you help? (8 Replies)
Discussion started by: chapmana
8 Replies

10. UNIX for Dummies Questions & Answers

if statements

I am trying to change this : Albert Einstein 52 Peter Scott 22 Hilary Smith 48 Joan Bakewell 30 Catherine Maguire 26 into Albert Einstein Pass Peter Scott Fail Hilary Smith Pass Joan Bakewell Fail Catherine Maguire Fail I have to use a if statement that says: if field 3 is... (2 Replies)
Discussion started by: lilas
2 Replies
Login or Register to Ask a Question