expr problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expr problem
# 1  
Old 08-31-2007
expr problem

Hi,
in my ksh script

expr 22 / 10 results as 2
but the actual result expected in 2.2.
how do i get that result. Please help

Thanks,
# 2  
Old 08-31-2007
/ is integer division
% modulus
may be you can use awk

awk 'BEGIN{print (22/10) }'

with parameters

awk -v a=$1 -v b=$2 '{print (a/b) }'

or

echo $number |awk '{print ($1/10)}'

Last edited by fazliturk; 08-31-2007 at 08:38 AM..
# 3  
Old 08-31-2007
expr works with integers.
Code:
 # echo 'scale=2;22/10' |bc
2.20

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If + expr

Hi I have bellow script: t1=`cat node1.txt | grep thread1 | cut -f2 -d '-'` t2=`cat node2.txt | grep thread2 | cut -f2 -d '-'` t3=`cat node1_rcat.txt | grep thread1 | cut -f2 -d '-'` t4=`cat node2_rcat.txt | grep thread2 | cut -f2 -d '-'` if ]; then echo "no restore" >> log.log... (6 Replies)
Discussion started by: primo102
6 Replies

2. Shell Programming and Scripting

Problem with expr command in shell script

Hi, I have used expr command to increment the date. for e.g., case 1 : echo $(date -d $(echo `expr 20010101 + 1`)) it returns Tue Jan 2 00:00:00 IST 2001 case 2: echo $(date -d $(echo `expr 20010101 - 1`)) it returns date: invalid date `20010100' please suggest me, how to... (3 Replies)
Discussion started by: nanthagopal
3 Replies

3. Shell Programming and Scripting

Error with expr - "expr: syntax error"

Hi All, I'm writing a shell script in KSH, where I want to store the filename, total record count and actual record count of all the source files. The source files reside in 4 different sub-folders under the same root folder. Below is code: #!/usr/bin/ksh... (6 Replies)
Discussion started by: jagari
6 Replies

4. UNIX for Dummies Questions & Answers

expr ?!

Hey there i want to subtract the content from $b from $a. Each variable has got 18 values (normal numbers from 0 - 99). How can i subtract them? I know i have to use the expr command, this is what i have till now: a=`cat Tabelle.dat | awk {'print $4'} | awk -F: {'print $1'}` b=`cat... (1 Reply)
Discussion started by: Mad van Bert
1 Replies

5. Shell Programming and Scripting

the expr \*

$ cat > mtable #!/bin/sh # #Script to test for loop # # if then echo "Error - Number missing form command line argument" echo "Syntax : $0 number" echo "Use to print multiplication table for given number" exit 1 fi n=$1 for i in 1 2 3 4 5 6 7 8 9 10 do echo "$n * $i = `expr $i \*... (1 Reply)
Discussion started by: jackel7777
1 Replies

6. Shell Programming and Scripting

test expr VS [ expr ]

What is the difference between test expr VS . For example : if test 5 -eq 6 echo "Wrong" and if echo "Wrong" bot will give the same output as Wrong. Now, what is the difference between these two? though they are producing the same result why we need two? Any answer will be... (2 Replies)
Discussion started by: ashok.g
2 Replies

7. Shell Programming and Scripting

Expr problem and other basic problems

Hello, I am new to the Bash scripting language, and was given a tutorial page on how to setup a file. However I am trying to use cygwin to run this file and it is not working. $ vi averagetime.sh # # # echo "Enter Dictorinary File Text " read dict echo "Enter Grid Name" read grid... (13 Replies)
Discussion started by: killerqb
13 Replies

8. Shell Programming and Scripting

Expr strange problem to me

Hi all, Please help me solve below issue. expr 04170000000 + 1 gives me -124967295 and offcourse I want this to be 04170000001 and it happens for some sort of number like some other 02300000000 02600000000 03800000000 I guess after exceeding certain range it is converting it somewhere... (2 Replies)
Discussion started by: Revansing
2 Replies

9. UNIX for Dummies Questions & Answers

problem with expr command

:) hi Unix gurus, Pls consider the following piece of code str='hello' length=echo $str|wc -c echo $length y= ` expr \( 80 - $length \) ` echo $y :confused: The last echo stmt is displaying 0 as the result. If i put direct value like 6 instead of $length in i 3rd stmt it is giving... (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

10. UNIX for Dummies Questions & Answers

expr problem

Hi, in my ksh script expr 22 / 10 results as 2 but the actual result expected in 2.2. how do i get that result. Please help Thanks, (4 Replies)
Discussion started by: kotasateesh
4 Replies
Login or Register to Ask a Question