LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help regarding bash script (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-regarding-bash-script-748041/)

asifbasha 08-17-2009 12:29 AM

need help regarding bash script
 
hai to all

i have written a bash script as follows in my /root/temp/foo
#foo -script name
#!/bin/bash
a=$1
b=$2
echo 'sum='$(a+b)
and also i have written php script /var/www/html/ as
<?php
$result=`/root/temp/foo 10 10`;
echo($result);
?>
every thing is fine and i am getting output as 20 in my browser but when i execute the bash script after changing mod 755 it show output as
0 . my question is that i have to pass values for php script to bash script and to see result by executing bash script not that php script ...
any ideas will help me
thank in advance to all....

chrism01 08-17-2009 12:47 AM

Shell arithmetic uses double parentheses: http://tldp.org/LDP/abs/html/arithexp.html

pixellany 08-17-2009 03:31 AM

Also, you have to use "$" to get the value of a variable---eg:
echo $(($a+$b))

But then, why not just:
echo $(($1+$2))
?

And why do you need "sum"?

chrism01 08-17-2009 06:53 PM

Actually, inside double parentheses, leading '$' is optional, and in fact if you use it to increment a var, its not allowed; see that link.


All times are GMT -5. The time now is 08:55 PM.