Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following files:

vars.txt

C=1234567890

Ascript.php

#!/usr/bin/php
<?php
var $C="$argv[1]";
echo "\n $C \n";

$con = mysql_connect('localhost','root','123') or die ("No connected");
mysql_select_db("test_database",$con);

if($C !=''){
  $rs = mysql_query("SELECT name FROM test_table WHERE `identifier`= '$C'");
  while($fields = mysql_fetch_row($rs)){
    $file = fopen("/var/log/Test/Result.txt","a") or die ("No created");
    for ($i=0, $x=count($fields); $i < $x; $i++){
      fputs($file, "$fields[$i]\n");
      fclose($file);
    }
  }
}
else {
echo "There is not identifier \n";
}
mysql_close($con);
?>

Bscript.sh

#!/bin/bash
C=`grep -oPa '[Cc]=[^\s]+' /var/log/Test/vars.txt|cut -d= -f2|sed -e 's/-//'`
echo -e "Identifier: $C"
`php -f /root/Ascript.php $C`

When I execute from cli:

[me]# php -f Ascript.php 1234567890

There's no problem!

But if I execute:

[me]# ./Bscript.sh

(Bscript has 755 permissions) I get this:

Identifier: 1234567890
./Bscript.sh: line 4: 1234567890: command not found

Even if I write the value directly in my Bscript.sh

...
`php -f /root/Ascript.php 1234567890`

I get the same error.

share|improve this question
up vote 2 down vote accepted

The problem is the backticks around the line

php -f /root/Ascript.php $C

They mean to the shell: "Execute the command in between, collect its output (only that to stdout) and then replace the backticks and everything in between with the output.

As there is noting else on that line the output (1234567890) is considered a command. Just remove the backticks.

You can check with by prepending an echo:

echo `php -f /root/Ascript.php $C`
share|improve this answer
    
Thanks my friend, that solved my problem! – M_Mike Nov 12 '14 at 22:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.