Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 01-05-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 May 2015, 9:03 PM EDT
Location: NM
Posts: 10,452
Thanks: 336
Thanked 860 Times in 799 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 05:25 AM
expr ?! Mad van Bert UNIX for Dummies Questions & Answers 1 09-06-2011 03:28 AM
the expr \* jackel7777 Shell Programming and Scripting 1 07-29-2011 10:29 PM
test expr VS [ expr ] ashok.g Shell Programming and Scripting 2 12-03-2009 06:42 AM
expr Nathe UNIX for Dummies Questions & Answers 5 01-22-2004 06:49 PM



All times are GMT -4. The time now is 05:24 AM.