how to use expr | Unix Linux Forums | Red Hat

  Go Back    


Red Hat Red Hat is the world's leading open source technology solutions provider with offerings including Red Hat Enterprise Linux (RHEL), Fedora, open source applications, security and systems management, virtualization, and Services Oriented Architecture (SOA) solutions.

how to use expr

Red Hat


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-30-2007
saikumarm80 saikumarm80 is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 December 2007, 12:03 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Java how to use expr

i am new to shell programming, currently using redhat linux of version
2.4.20-8.
i have problem in executing expr command in the following shell script

$ x=5
$ x='expr $x + 1'
$ echo $x

the output is displaying always
expr $x + 1

Pls guide me for the above query
Sponsored Links
    #2  
Old 11-30-2007
manzier manzier is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 1 December 2009, 3:24 PM EST
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
how to use expr

You need to use back tics not single quotes

x=`expr $x + 1`
Sponsored Links
    #3  
Old 01-05-2009
beni22sof beni22sof is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 24 October 2009, 3:22 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I tried to use expr for multiplication, but got an error. I used '*' symbol. Can you tell me what's the problem, or if there is another way? Thanks
    #4  
Old 01-05-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 21 November 2014, 4:36 PM EST
Location: NM
Posts: 10,279
Thanks: 287
Thanked 814 Times in 756 Posts
escape the * it is a shell metacharacter

Code:
a=$( expr 13 \* 3)
# or
a=`expr 13 \* 3`

The Following User Says Thank You to jim mcnamara For This Useful Post:
jeyashree (03-06-2011)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error with expr - "expr: syntax error" jagari Shell Programming and Scripting 6 02-24-2012 06:25 AM
expr ?! Mad van Bert UNIX for Dummies Questions & Answers 1 09-06-2011 04:28 AM
the expr \* jackel7777 Shell Programming and Scripting 1 07-29-2011 11:29 PM
test expr VS [ expr ] ashok.g Shell Programming and Scripting 2 12-03-2009 07:42 AM
expr Nathe UNIX for Dummies Questions & Answers 5 01-22-2004 07:49 PM



All times are GMT -4. The time now is 01:47 AM.