![]() |
|
|
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 |
| Problem in division | rochitsharma | UNIX for Dummies Questions & Answers | 9 | 11-25-2008 10:17 PM |
| what does the operation '>&' mean in a shell script | cy163 | UNIX for Dummies Questions & Answers | 3 | 05-17-2008 02:54 PM |
| division in shell scripts | esham | Shell Programming and Scripting | 6 | 11-30-2005 06:42 AM |
| Cannot adjust division | jav_v | Filesystems, Disks and Memory | 1 | 08-20-2002 09:50 AM |
| division problem | inquirer | Shell Programming and Scripting | 3 | 04-02-2002 11:03 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
division operation in shell script
Hi guys I am trying to divide 2 variables that I got during the execution of script, but I unable to divide the variables. pls help. Hers is the code. Code:
num_tasks=`sqlplus -s batch_user/batch_user@acsblest << EOF1 set heading off SET FEEDBACK OFF SET PAGESIZE 0 SET LINESIZE 900 select cp_num_run_ from fusionhc_chk where cc_alias = 'eCustomerCMEObjMgr_enu'; EOF1` echo $num_tasks max_tasks=`sqlplus -s batch_user/batch_user@acsblest << EOF2 set heading off SET FEEDBACK OFF SET PAGESIZE 0 SET LINESIZE 900 select cp_max_task from fusionhc_chk where cc_alias = 'eCustomerCMEObjMgr_enu'; EOF2` echo $max_tasks per_load=$num_tasks/$max_tasks echo $per_load if [ "$per_load" -gt "0.95" ] then echo "not good" fi exit i did a set -x and I get this Code:
3 20 3/20 plz help.. |
|
||||
|
try this for Integer division
per_load=$(($num_tasks/$max_tasks))
This would give you only integer out put. Not sure if direct decimal o/p is possible . You could use awk to get the desired decimal out. --Manish |
|
||||
|
First off, SQL provide for division: Code:
result=\
`sqlplus -s batch_user/batch_user@acsblest << EOF1
set heading off
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
select cp_num_run_ / cp_max_task
from fusionhc_chk
where cc_alias = 'eCustomerCMEObjMgr_enu';
EOF1`
echo $result
Floating point division in scripts depends on the shell - a general solution : Code:
result=`echo "$num_tasks / max_tasks " | bc -l` echo $result |
|
||||
|
thank you guys.. i modified the code as follows and got the output, but still i am unable to compare the two numbers, VGERSH, i know you explained this part.. but I am sorry to tell that I am unable to understand theat part. my understanding of shell script is very poor. I used sql to do the division. here is the code and set -x output. Code:
num_tasks=`sqlplus -s batch_user/batch_user@$SIEBEL_DB_ORACLESID << EOF2
set heading off
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
select cp_num_run_ / cp_max_task
from fusionhc_chk
where cc_alias = 'eCustomerCMEObjMgr_enu';
EOF2`
echo $num_tasks
set -x
if [ $num_tasks > 0.95 ]
then
echo "not good"
fi
exit
set -x output Code:
.15 + [ .15 ] + 1> 0.95 + echo not good not good + exit |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|