LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2004, 01:06 AM   #1
subu_s
Member
 
Registered: Jun 2004
Posts: 36

Rep: Reputation: 15
Usage of 'expr' command


Hi friends,
Wld be a very basic question for most of you.

I need to use expr to do something like '10 / 20 * 100' and the result should be 50

expr gives me a syntax error .

Pls. help.

Regds,
Subu
 
Old 12-03-2004, 01:17 AM   #2
subu_s
Member
 
Registered: Jun 2004
Posts: 36

Original Poster
Rep: Reputation: 15
Seems that I had not escaped the operators '*' and '/'
Is working fine now
 
Old 12-03-2004, 01:23 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Bash (prob all shells) only does integer maths. You'll need to use the bc tool to get the right answer.
eg:
t=$((10/20*100))
echo $t
0

would be the same with expr eg
t=`expr 10 / 20`
echo $t
0

....
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sudo command usage??? pagadala_cs Linux - Software 1 12-24-2004 10:13 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
another odd command usage citrus Linux - Software 13 05-11-2004 03:26 PM
usage of rpm command woja Linux - Newbie 4 01-30-2004 04:32 AM
rm command usage big_orange Linux - General 3 11-04-2003 04:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration