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

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to use expr saikumarm80 Red Hat 3 01-05-2009 03:52 PM
problem with expr command ravi raj kumar UNIX for Dummies Questions & Answers 8 09-03-2007 05:59 AM
expr problem kotasateesh Shell Programming and Scripting 2 08-31-2007 09:00 AM
expr Nathe UNIX for Dummies Questions & Answers 5 01-22-2004 07:49 PM
how do I get the value of expr with ksh krishna UNIX for Advanced & Expert Users 3 08-26-2001 02:51 PM

Closed Thread
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
  #1 (permalink)  
Old 08-31-2007
kotasateesh kotasateesh is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 39
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 (permalink)  
Old 08-31-2007
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
When using expr the '/' operation is not divide but returns the quotient. You need to use bc or something similar, for example:

Code:
echo "scale=2;22/10" | bc
  #3 (permalink)  
Old 08-31-2007
arunkumar_mca arunkumar_mca is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 256
Hi All,

i tried to assign it by the below way

$ test="scale=2;22/10" | bc
$ echo $test

but i got no output

please let me know ,why it is not getting assigned .. Am i wrong in anthing please let me know.

Thanks in Advance,
Arun
  #4 (permalink)  
Old 08-31-2007
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
Quote:
Originally Posted by arunkumar_mca View Post
$ test="scale=2;22/10" | bc
$ echo $test
What you are doing here is assigning the 'standard output' of running '"scale=2;22/10" | bc' to the variable 'test'. Unfortunately that is not a valid command and the only output is to standard error. What you need is:

Code:
test=`echo "scale=2;22/10" | bc`
echo $test
  #5 (permalink)  
Old 09-03-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by kotasateesh View Post
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,
you can use this syntax also--

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

Thanks
Namish Tiwari
Closed Thread

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 10:15 PM.


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