The UNIX and Linux Forums  
Hello and Welcome from United States 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
expr problem kotasateesh Shell Programming and Scripting 2 08-31-2007 08:00 AM
expr Nathe UNIX for Dummies Questions & Answers 5 01-22-2004 07:49 PM
Problems with expr command rooh UNIX for Dummies Questions & Answers 2 01-17-2003 11:03 AM
how do I get the value of expr with ksh krishna UNIX for Advanced & Expert Users 3 08-26-2001 01: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 06-28-2005
benu302000 benu302000 is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 10
Problems with expr

I'm writing a unix script that simply does some basic command line stuff for a whole lot of similar directories (ls *.dat > foo.bar). Its my first script ever, and its going ok, except I can't, for the life of me, figure out how to get arithmetic to work in the script.

FIVE=5
MY_NUMBER='expr $FIVE + 3'
echo $MY_NUMBER

even this simple script either outputs "expr $FIVE + 3" at the command line, or fails utterly. Any Ideas? I'm writing it for the bourne shell, on a SOLARIS machine.
  #2 (permalink)  
Old 06-28-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Use backquotes (`), not single quotes (').
  #3 (permalink)  
Old 06-28-2005
benu302000 benu302000 is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 10
Ah, Didn't even realized those existed until now, thank you
  #4 (permalink)  
Old 06-28-2005
sssow sssow is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 179
I prefer to use let in this case as follows
five=5
let five=$five+3
echo $five
  #5 (permalink)  
Old 06-28-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
sh on Solaris has no built in arithmetic. It's a very old shell.
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 08:43 AM.


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