evaluating lengthy expressions in `
|
Original Message
|
Name: vastare
Date: June 22, 2005 at 04:31:26 Pacific
Subject: evaluating lengthy expressions in `OS: SolarisCPU/Ram: ? |
Comment: How to evaluate lengthy expressions by overiding precedance of operators using 'expr' command in shell scripting? eg. x=12 $x + 1 \* 2 --> Gives 14 but we want it to be 26 i.e ($x + 1) * 2
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: nails
Date: June 22, 2005 at 10:49:51 Pacific
|
Reply: (edit)Hi: You need to escape the parenthesis: i=$(expr \( $x + 1 \) \* 2 ) echo $i But if you are running Solaris, you have ksh so why don't you use the ksh arithmetic: #!/bin/ksh x=12 r2=$(( $((x+1)) * 2)) echo "r2=$r2"
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: vastare
Date: June 22, 2005 at 22:01:22 Pacific
|
Reply: (edit)Hi Nails, Thanks, One more request. Could you suggest any perticular site belongs to shell script which makes me competent in shell programming. I am asking this question as I got confused with lots of site which I get if I search through google. Thanks in advance. Vastare
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: nails
Date: June 23, 2005 at 08:03:04 Pacific
|
Reply: (edit)I can't really recommend anything for "learning" shell programming, but here are two sites that have good examples: http://www.shelldorado.com Check out the links. They are excellent. Also, the Tower shell script link is quite good: http://www.cit.gu.edu.au/~anthony/info/shell/
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: