|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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` |
|
#3
|
|||
|
|||
|
Quote:
Well, and in Korn shell you can simply write let x=x+10 Regards ![]() |
|
#4
|
|||
|
|||
|
not sure this is correct
Quote:
anyway, bourne, korn, c or bash .... the probl is this guy does not know/respect the syntax. |
|
#5
|
|||
|
|||
|
Quote:
I am sure guggach, in Korn shell let x=x+10 is correct. In bash, too. Try it. Regards zlutovsky |
|
#6
|
|||
|
|||
|
Quote:
Code:
#!/bin/ksh
typeset -i x=5
(( x+=10 ))
echo "x->[${x}]"
|
|
#7
|
|||
|
|||
|
thanks
thanks everybody for helping me!
![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > simple expr |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|