UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 17th, 2005, 07:23 PM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
simple expr

if program such
x=0
for i in 1 2 3
do
x=' expr $x + 10 '
echo $i $x
done

the output should be:
1 10
2 20
3 30

but why i get output such:
1 expr $x + 10
2 expr $x + 10
3 expr $x + 10

it didn't do the calculating?
why?
i have to pass the variable to continue my assignment

Reply With Quote
  #2  
Old January 18th, 2005, 05:48 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,098 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 8 h 44 m 33 sec
Reputation Power: 9
you are using
x=' expr $x + 10 '
instead of
x=`expr $x + 10`
nota: no spaces and the single quote avoids the replacement
of $x
on *nix 'bc' is better then 'expr'
x=`echo 23456/22¦bc`

Reply With Quote
  #3  
Old January 18th, 2005, 06:10 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by guggach
you are using
x=' expr $x + 10 '
instead of
x=`expr $x + 10`
nota: no spaces and the single quote avoids the replacement
of $x
on *nix 'bc' is better then 'expr'
x=`echo 23456/22¦bc`



Well, and in Korn shell you can simply write

let x=x+10

Regards

Reply With Quote
  #4  
Old January 18th, 2005, 06:40 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,098 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 8 h 44 m 33 sec
Reputation Power: 9
not sure this is correct
Quote:
let x=x+10

anyway, bourne, korn, c or bash ....
the probl is this guy does not know/respect the syntax.

Reply With Quote
  #5  
Old January 18th, 2005, 08:02 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by guggach
not sure this is correct

anyway, bourne, korn, c or bash ....
the probl is this guy does not know/respect the syntax.



I am sure guggach, in Korn shell

let x=x+10

is correct. In bash, too. Try it.

Regards zlutovsky

Reply With Quote
  #6  
Old January 18th, 2005, 12:23 PM
vgersh99 vgersh99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 47 vgersh99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 48 m 21 sec
Reputation Power: 4
Send a message via AIM to vgersh99 Send a message via MSN to vgersh99 Send a message via Yahoo to vgersh99
Quote:
Originally Posted by zlutovsky
I am sure guggach, in Korn shell

let x=x+10

is correct. In bash, too. Try it.

Regards zlutovsky


Code:
#!/bin/ksh

typeset -i x=5

(( x+=10 ))

echo "x->[${x}]"

Reply With Quote
  #7  
Old January 23rd, 2005, 09:51 PM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
thanks

thanks everybody for helping me!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > simple expr


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT