LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-17-2009, 01:29 AM   #1
asifbasha
Member
 
Registered: Feb 2009
Posts: 98

Rep: Reputation: 15
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....
 
Old 08-17-2009, 01:47 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Shell arithmetic uses double parentheses: http://tldp.org/LDP/abs/html/arithexp.html
 
Old 08-17-2009, 04:31 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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"?
 
Old 08-17-2009, 07:53 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 05:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 08:01 PM
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 07:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration